You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by kn...@apache.org on 2021/05/19 08:09:27 UTC
[flink-jira-bot] 05/47: [FLINK-22032] add Rule 3 (logging only)
This is an automated email from the ASF dual-hosted git repository.
knaufk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink-jira-bot.git
commit 6f4e13c295cd09789d509db49496956751e7d9cd
Author: Konstantin Knauf <kn...@gmail.com>
AuthorDate: Fri Apr 9 13:42:42 2021 +0200
[FLINK-22032] add Rule 3 (logging only)
---
Makefile | 2 +-
README.md | 0
config.yaml | 6 ++++
flink_jira_bot.py | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 97 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index 40ca9f7..677c9cc 100644
--- a/Makefile
+++ b/Makefile
@@ -12,7 +12,7 @@ $(VENV)/bin/activate: requirements.txt
venv: $(VENV)/bin/activate
run: venv
- ./$(VENV)/bin/python3 flink_jira_bot/flink_jira_bot.py
+ ./$(VENV)/bin/python3 flink_jira_bot.py
format: venv
./$(VENV)/bin/python3 -m black .
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..e69de29
diff --git a/config.yaml b/config.yaml
new file mode 100644
index 0000000..d77f815
--- /dev/null
+++ b/config.yaml
@@ -0,0 +1,6 @@
+stale_minor:
+ stale_days: 180
+ warning_days: 7
+ label: "stale-minor"
+ comment: 'This issue (and any of its Sub-Tasks) has not been updated for {stale_days} days. So, it has been labeled "{label}". If you are still affected by this bug or are still interested in this issue, please give an update and remove the label. In {warning_days} days the issue will be closed automatically.'
+
diff --git a/flink_jira_bot.py b/flink_jira_bot.py
new file mode 100644
index 0000000..a092399
--- /dev/null
+++ b/flink_jira_bot.py
@@ -0,0 +1,90 @@
+from atlassian import Jira
+import logging
+import confuse
+import os
+import abc
+
+
+class FlinkJiraRule:
+ __metaclass__ = abc.ABCMeta
+
+ def __init__(self, jira_client, config):
+ self.jira_client = jira_client
+ self.config = config
+
+ def has_recently_updated_subtask(self, parent, updated_within_days):
+ find_subtasks_updated_within = (
+ f"parent = {parent} AND updated > startOfDay(-{updated_within_days}d)"
+ )
+ issues = self.jira_client.jql(find_subtasks_updated_within, limit=1)
+ return issues["total"] > 0
+
+ @abc.abstractmethod
+ def run(self):
+ return
+
+
+class Rule3(FlinkJiraRule):
+ def __init__(self, jira_client, config):
+ super().__init__(jira_client, config)
+ self.stale_days = config["stale_minor"]["stale_days"].get()
+ self.warning_days = config["stale_minor"]["warning_days"].get()
+ self.label = config["stale_minor"]["label"].get()
+ self.comment = config["stale_minor"]["comment"].get()
+
+ def run(self):
+ self.close_tickets_marked_stale()
+ self.mark_stale_tickets_stale()
+
+ def close_tickets_marked_stale(self):
+
+ minor_tickets_marked_stale = f'project=FLINK AND Priority = Minor AND resolution = Unresolved AND labels in ("{self.label}") AND updated < startOfDay(-{self.warning_days}d)'
+ logging.info(
+ f"Looking for minor tickets, which were previously marked as stale: {minor_tickets_marked_stale}"
+ )
+ issues = jira.jql(minor_tickets_marked_stale, limit=10000)
+
+ for issue in issues["issues"]:
+ key = issue["key"]
+ logging.info(
+ f"Found https://issues.apache.org/jira/browse/{key}. It is now closed due to inactivity."
+ )
+
+ def mark_stale_tickets_stale(self):
+
+ stale_minor_tickets = f"project = FLINK AND Priority = Minor AND resolution = Unresolved AND updated < startOfDay(-{self.stale_days}d)"
+ logging.info(
+ f"Looking for minor tickets, which are stale: {stale_minor_tickets}"
+ )
+ issues = self.jira_client.jql(stale_minor_tickets, limit=10000)
+
+ for issue in issues["issues"]:
+ key = issue["key"]
+ issue = self.jira_client.get_issue(key)
+
+ if not self.has_recently_updated_subtask(key, self.stale_days):
+ logging.info(
+ f"Found https://issues.apache.org/jira/browse/{key}. It is marked stale now."
+ )
+
+ else:
+ logging.debug(
+ f"Found https://issues.apache.org/jira/browse/{key}, but is has recently updated Subtasks. Ignoring for now."
+ )
+
+
+if __name__ == "__main__":
+
+ logging.getLogger().setLevel(logging.INFO)
+
+ config = confuse.Configuration("flink-jira-bot", __name__)
+ config.set_file("config.yaml")
+
+ jira = Jira(
+ url="https://issues.apache.org/jira",
+ username="flink-jira-bot",
+ password=os.environ["JIRA_PASSWORD"],
+ )
+
+ rule_3 = Rule3(jira, config)
+ rule_3.run()