From f352184c73520c68ccc344cb6a71f1f7fbb136d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Perdig=C3=A3o?= Date: Thu, 28 Nov 2024 16:19:28 -0300 Subject: [PATCH 01/19] Update jiralib.py --- jiralib.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/jiralib.py b/jiralib.py index a6bf0e9..9b831c3 100644 --- a/jiralib.py +++ b/jiralib.py @@ -99,6 +99,29 @@ def create_hook( return resp.json() + def attach_file(self, issue_key, fname, fp): + ''' + This function is currently needed, because the version of the 'jira' module + we depend on (2.0.0) has a bug that makes file attachments crash for + recent versions of python. This has been fixed in version 3.0.0, which, + unfortunately is not yet available via pip. + See: + https://github.com/pycontribs/jira/issues/890 + https://github.com/pycontribs/jira/issues/985 + TODO: Remove this function once `jira:3.0.0` is available via pip. + ''' + resp = requests.post( + '{api_url}/rest/api/2/issue/{issue_key}/attachments'.format( + api_url=self.url, + issue_key=issue_key + ), + headers={'X-Atlassian-Token': 'no-check'}, + auth=self.auth(), + files={'file': (fname, fp)}, + timeout=util.REQUEST_TIMEOUT + ) + resp.raise_for_status() + class JiraProject: def __init__(self, jira, projectkey, endstate, reopenstate, labels): From 83ab015dd6aa1d117fd6abab789144903e496178 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Perdig=C3=A3o?= Date: Thu, 28 Nov 2024 16:35:11 -0300 Subject: [PATCH 02/19] Update jiralib.py --- jiralib.py | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/jiralib.py b/jiralib.py index 9b831c3..8c2c863 100644 --- a/jiralib.py +++ b/jiralib.py @@ -99,30 +99,6 @@ def create_hook( return resp.json() - def attach_file(self, issue_key, fname, fp): - ''' - This function is currently needed, because the version of the 'jira' module - we depend on (2.0.0) has a bug that makes file attachments crash for - recent versions of python. This has been fixed in version 3.0.0, which, - unfortunately is not yet available via pip. - See: - https://github.com/pycontribs/jira/issues/890 - https://github.com/pycontribs/jira/issues/985 - TODO: Remove this function once `jira:3.0.0` is available via pip. - ''' - resp = requests.post( - '{api_url}/rest/api/2/issue/{issue_key}/attachments'.format( - api_url=self.url, - issue_key=issue_key - ), - headers={'X-Atlassian-Token': 'no-check'}, - auth=self.auth(), - files={'file': (fname, fp)}, - timeout=util.REQUEST_TIMEOUT - ) - resp.raise_for_status() - - class JiraProject: def __init__(self, jira, projectkey, endstate, reopenstate, labels): self.jira = jira @@ -184,9 +160,9 @@ def save_repo_state(self, repo_id, state, issue_key="-"): self.j.delete_attachment(a.id) # attach the new state file - self.jira.attach_file( - i.key, repo_id_to_fname(repo_id), util.state_to_json(state) - ) + attachment = StringIO() + attachment.write(util.state_to_json(state)) + self.jira.add_attachment(issue=i, attachment=attachment, filename=repo_id_to_fname(repo_id)) def create_issue( self, From 66f82060c30e8d36fa78bf66d393a3bbede35f25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Perdig=C3=A3o?= Date: Thu, 28 Nov 2024 16:36:51 -0300 Subject: [PATCH 03/19] Update jiralib.py --- jiralib.py | 1 + 1 file changed, 1 insertion(+) diff --git a/jiralib.py b/jiralib.py index 8c2c863..3ca3f90 100644 --- a/jiralib.py +++ b/jiralib.py @@ -1,4 +1,5 @@ from jira import JIRA +from io import StringIO import re import util import logging From e2364426753545cbc7dfc426f9c5d6bf6957cb93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Perdig=C3=A3o?= Date: Thu, 28 Nov 2024 16:41:16 -0300 Subject: [PATCH 04/19] Update Pipfile --- Pipfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pipfile b/Pipfile index d80ff30..2289992 100644 --- a/Pipfile +++ b/Pipfile @@ -6,7 +6,7 @@ verify_ssl = true [packages] flask = "~=2.3.0" requests = "~=2.32.3" -jira = "~=3.0.0" +jira = "~=3.8.0" logging-formatter-anticrlf = "~=1.2.1" [dev-packages] From cb087ffc9f13cae9e1bf593a1cf32f44df97c1bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Perdig=C3=A3o?= Date: Thu, 28 Nov 2024 16:46:28 -0300 Subject: [PATCH 05/19] Update jiralib.py --- jiralib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jiralib.py b/jiralib.py index 3ca3f90..771d2d4 100644 --- a/jiralib.py +++ b/jiralib.py @@ -163,7 +163,7 @@ def save_repo_state(self, repo_id, state, issue_key="-"): # attach the new state file attachment = StringIO() attachment.write(util.state_to_json(state)) - self.jira.add_attachment(issue=i, attachment=attachment, filename=repo_id_to_fname(repo_id)) + self.j.add_attachment(issue=i, attachment=attachment, filename=repo_id_to_fname(repo_id)) def create_issue( self, From 5dc3cd904669e68b3f3bbafc5dce66356b52acc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Perdig=C3=A3o?= Date: Thu, 28 Nov 2024 16:57:06 -0300 Subject: [PATCH 06/19] Update cli.py --- cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli.py b/cli.py index c2aa558..6472a49 100644 --- a/cli.py +++ b/cli.py @@ -100,7 +100,7 @@ def sync(args): else: state = {} - s = Sync(github, jira_project, direction=direction_str_to_num(args.direction)) + s = Sync(github, jira_project, direction=direction_str_to_num(args.direction_base)) s.sync_repo(repo_id, states=state) if args.state_file: From f892303935a22ebaf7813dcab2af8552be9f99fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Perdig=C3=A3o?= Date: Thu, 28 Nov 2024 17:04:04 -0300 Subject: [PATCH 07/19] Update cli.py --- cli.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cli.py b/cli.py index 6472a49..a49d10f 100644 --- a/cli.py +++ b/cli.py @@ -100,6 +100,8 @@ def sync(args): else: state = {} + print args + s = Sync(github, jira_project, direction=direction_str_to_num(args.direction_base)) s.sync_repo(repo_id, states=state) From 5d01b17374b7c4e488953da0100c3e972e838479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Perdig=C3=A3o?= Date: Thu, 28 Nov 2024 17:04:46 -0300 Subject: [PATCH 08/19] Update cli.py --- cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli.py b/cli.py index a49d10f..4948deb 100644 --- a/cli.py +++ b/cli.py @@ -102,7 +102,7 @@ def sync(args): print args - s = Sync(github, jira_project, direction=direction_str_to_num(args.direction_base)) + s = Sync(github, jira_project, direction=direction_str_to_num(args.direction)) s.sync_repo(repo_id, states=state) if args.state_file: From 614b49515ea0edd46ee8949ccbde7e1db9452639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Perdig=C3=A3o?= Date: Thu, 28 Nov 2024 17:05:57 -0300 Subject: [PATCH 09/19] Update cli.py --- cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli.py b/cli.py index 4948deb..2d6de90 100644 --- a/cli.py +++ b/cli.py @@ -100,7 +100,7 @@ def sync(args): else: state = {} - print args + print(args) s = Sync(github, jira_project, direction=direction_str_to_num(args.direction)) s.sync_repo(repo_id, states=state) From 2abf7b11c6d99bff92362d81365c9931ee2af019 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Perdig=C3=A3o?= Date: Thu, 28 Nov 2024 17:17:41 -0300 Subject: [PATCH 10/19] Update cli.py --- cli.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cli.py b/cli.py index 2d6de90..9b05c3e 100644 --- a/cli.py +++ b/cli.py @@ -105,10 +105,17 @@ def sync(args): s = Sync(github, jira_project, direction=direction_str_to_num(args.direction)) s.sync_repo(repo_id, states=state) + print("1") + if args.state_file: + print("2") util.state_to_file(args.state_file, state) + print("2.1") elif args.state_issue: + print("3") jira_project.save_repo_state(repo_id, state, args.state_issue) + print("3.1") + print("4") def check_hooks(args): From 57789f8599b0d1e6fc81231bded685051b89e0c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Perdig=C3=A3o?= Date: Thu, 28 Nov 2024 17:34:54 -0300 Subject: [PATCH 11/19] Update cli.py --- cli.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/cli.py b/cli.py index 9b05c3e..e1cbecc 100644 --- a/cli.py +++ b/cli.py @@ -100,23 +100,13 @@ def sync(args): else: state = {} - print(args) - s = Sync(github, jira_project, direction=direction_str_to_num(args.direction)) s.sync_repo(repo_id, states=state) - print("1") - if args.state_file: - print("2") util.state_to_file(args.state_file, state) - print("2.1") elif args.state_issue: - print("3") jira_project.save_repo_state(repo_id, state, args.state_issue) - print("3.1") - print("4") - def check_hooks(args): pass From a3b6f32bbedde8e6470d1ad04e28e85389f1e297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Perdig=C3=A3o?= Date: Thu, 28 Nov 2024 17:35:45 -0300 Subject: [PATCH 12/19] Update cli.py --- cli.py | 1 - 1 file changed, 1 deletion(-) diff --git a/cli.py b/cli.py index e1cbecc..76072b9 100644 --- a/cli.py +++ b/cli.py @@ -111,7 +111,6 @@ def sync(args): def check_hooks(args): pass - def install_hooks(args): if not args.hook_url: fail("No hook URL specified!") From ee2912fc001ddebe73cd3779c29c65c5de3c5574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Perdig=C3=A3o?= Date: Thu, 28 Nov 2024 17:36:42 -0300 Subject: [PATCH 13/19] Update cli.py --- cli.py | 1 - 1 file changed, 1 deletion(-) diff --git a/cli.py b/cli.py index 76072b9..f7bfebd 100644 --- a/cli.py +++ b/cli.py @@ -107,7 +107,6 @@ def sync(args): util.state_to_file(args.state_file, state) elif args.state_issue: jira_project.save_repo_state(repo_id, state, args.state_issue) - def check_hooks(args): pass From 5507dc7a05b6f712d9a8dc77c59b46dec39d7f57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Perdig=C3=A3o?= Date: Thu, 28 Nov 2024 17:37:03 -0300 Subject: [PATCH 14/19] Update cli.py --- cli.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cli.py b/cli.py index f7bfebd..6c81551 100644 --- a/cli.py +++ b/cli.py @@ -107,8 +107,11 @@ def sync(args): util.state_to_file(args.state_file, state) elif args.state_issue: jira_project.save_repo_state(repo_id, state, args.state_issue) + + def check_hooks(args): pass + def install_hooks(args): if not args.hook_url: From 9e4e6a3211a90d7a8f0f3405e330147da1d01c0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Perdig=C3=A3o?= Date: Thu, 28 Nov 2024 17:37:25 -0300 Subject: [PATCH 15/19] Update cli.py --- cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli.py b/cli.py index 6c81551..c2aa558 100644 --- a/cli.py +++ b/cli.py @@ -111,7 +111,7 @@ def sync(args): def check_hooks(args): pass - + def install_hooks(args): if not args.hook_url: From 9e0edb3e6893ba3ba922c140e4d3bdc1c0c4a0d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Perdig=C3=A3o?= Date: Thu, 28 Nov 2024 22:33:47 -0300 Subject: [PATCH 16/19] Update action.yml --- action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/action.yml b/action.yml index 544f767..57cab1b 100644 --- a/action.yml +++ b/action.yml @@ -67,5 +67,6 @@ runs: --jira-project "$INPUTS_JIRA_PROJECT" \ --jira-labels "$INPUTS_JIRA_LABELS" \ --direction "$INPUTS_SYNC_DIRECTION" \ + --state-issue - ] --issue-end-state "$INPUTS_ISSUE_END_STATE" \ --issue-reopen-state "$INPUTS_ISSUE_REOPEN_STATE" From 8f41d12a17b91d3da29b9612fe834a36748f1b8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Perdig=C3=A3o?= Date: Thu, 28 Nov 2024 22:34:04 -0300 Subject: [PATCH 17/19] Update action.yml --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 57cab1b..00044da 100644 --- a/action.yml +++ b/action.yml @@ -67,6 +67,6 @@ runs: --jira-project "$INPUTS_JIRA_PROJECT" \ --jira-labels "$INPUTS_JIRA_LABELS" \ --direction "$INPUTS_SYNC_DIRECTION" \ - --state-issue - ] + --state-issue - \ --issue-end-state "$INPUTS_ISSUE_END_STATE" \ --issue-reopen-state "$INPUTS_ISSUE_REOPEN_STATE" From 3c474dd4c94ca6aae4f0981b07972a338187c250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Perdig=C3=A3o?= Date: Thu, 28 Nov 2024 22:43:14 -0300 Subject: [PATCH 18/19] Update action.yml --- action.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 00044da..22cc748 100644 --- a/action.yml +++ b/action.yml @@ -27,6 +27,10 @@ inputs: description: 'Which direction to synchronize in ("gh2jira", "jira2gh" or "both")' required: false default: 'both' + issue_state_key: + description: 'Name of the task that will contain the state file. If not provided it will be created a default one.' + required: false + default: '-' issue_end_state: description: 'Custom end state' required: false @@ -51,6 +55,7 @@ runs: INPUTS_SYNC_DIRECTION: ${{ inputs.sync_direction }} INPUTS_ISSUE_END_STATE: ${{ inputs.issue_end_state }} INPUTS_ISSUE_REOPEN_STATE: ${{ inputs.issue_reopen_state }} + INPUTS_ISSUE_STATE_KEY: ${{ inputs.issue_state_key }} run: | pip3 install pipenv pipenv install @@ -67,6 +72,6 @@ runs: --jira-project "$INPUTS_JIRA_PROJECT" \ --jira-labels "$INPUTS_JIRA_LABELS" \ --direction "$INPUTS_SYNC_DIRECTION" \ - --state-issue - \ + --state-issue "INPUTS_ISSUE_STATE_KEY" \ --issue-end-state "$INPUTS_ISSUE_END_STATE" \ --issue-reopen-state "$INPUTS_ISSUE_REOPEN_STATE" From 3c8f71f21d9a2da10cce3f43ecdd215070239560 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Perdig=C3=A3o?= Date: Thu, 28 Nov 2024 22:46:22 -0300 Subject: [PATCH 19/19] Update action.yml --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 22cc748..9edd65a 100644 --- a/action.yml +++ b/action.yml @@ -72,6 +72,6 @@ runs: --jira-project "$INPUTS_JIRA_PROJECT" \ --jira-labels "$INPUTS_JIRA_LABELS" \ --direction "$INPUTS_SYNC_DIRECTION" \ - --state-issue "INPUTS_ISSUE_STATE_KEY" \ + --state-issue "$INPUTS_ISSUE_STATE_KEY" \ --issue-end-state "$INPUTS_ISSUE_END_STATE" \ --issue-reopen-state "$INPUTS_ISSUE_REOPEN_STATE"