Skip to content

Commit

Permalink
Add support for GitHub issues closed as not planned (#47)
Browse files Browse the repository at this point in the history
* Add support for GitHub issues closed as not planned
* Add payload from @beliaev-maksim
* Add unit tests
  • Loading branch information
carlcsaposs-canonical authored Aug 15, 2024
1 parent c06b067 commit 0f252f4
Show file tree
Hide file tree
Showing 6 changed files with 476 additions and 3 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ settings:
# Dictionary mapping GitHub issue status to Jira issue status
status_mapping:
opened: Untriaged
closed: done
closed: done
# (Optional) Use different status for GitHub issues closed as not planned (instead of closed as
# completed)
# https://github.blog/changelog/2022-03-10-the-new-github-issues-march-10th-update/#%F0%9F%95%B5%F0%9F%8F%BD%E2%99%80%EF%B8%8F-issue-closed-reasons
# If not specified, `closed` status will be used.
not_planned: rejected

# (Optional) Jira project components that should be attached to the created issue
# Component names are case-sensitive
Expand Down
9 changes: 7 additions & 2 deletions github_jira_sync_app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ async def bot(request: Request, payload: dict = Body(...)):

opened_status = settings["status_mapping"]["opened"]
closed_status = settings["status_mapping"]["closed"]
not_planned_status = settings["status_mapping"].get("not_planned", closed_status)

msg = ""
if not existing_issues:
Expand All @@ -274,8 +275,12 @@ async def bot(request: Request, payload: dict = Body(...)):
else:
jira_issue = existing_issues[0]
if payload["action"] == "closed":
jira.transition_issue(jira_issue, closed_status)
return {"msg": "Closed existing Jira Issue"}
if payload["issue"]["state_reason"] == "not_planned":
jira.transition_issue(jira_issue, not_planned_status)
return {"msg": "Closed existing Jira Issue as not planned"}
else:
jira.transition_issue(jira_issue, closed_status)
return {"msg": "Closed existing Jira Issue"}
elif payload["action"] == "reopened":
jira.transition_issue(jira_issue, opened_status)
return {"msg": "Reopened existing Jira Issue"}
Expand Down
207 changes: 207 additions & 0 deletions tests/unit/payloads/issue_closed_as_completed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
{
"action": "closed",
"issue": {
"url": "https://api.github.com/repos/beliaev-maksim/test-ci/issues/30",
"repository_url": "https://api.github.com/repos/beliaev-maksim/test-ci",
"labels_url": "https://api.github.com/repos/beliaev-maksim/test-ci/issues/30/labels{/name}",
"comments_url": "https://api.github.com/repos/beliaev-maksim/test-ci/issues/30/comments",
"events_url": "https://api.github.com/repos/beliaev-maksim/test-ci/issues/30/events",
"html_url": "https://github.com/beliaev-maksim/test-ci/issues/30",
"id": 2466054162,
"node_id": "I_kwDOI7Rtfs6S_QAS",
"number": 30,
"title": "new test",
"user": {
"login": "beliaev-maksim",
"id": 51964909,
"node_id": "MDQ6VXNlcjUxOTY0OTA5",
"avatar_url": "https://avatars.githubusercontent.com/u/51964909?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/beliaev-maksim",
"html_url": "https://github.com/beliaev-maksim",
"followers_url": "https://api.github.com/users/beliaev-maksim/followers",
"following_url": "https://api.github.com/users/beliaev-maksim/following{/other_user}",
"gists_url": "https://api.github.com/users/beliaev-maksim/gists{/gist_id}",
"starred_url": "https://api.github.com/users/beliaev-maksim/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/beliaev-maksim/subscriptions",
"organizations_url": "https://api.github.com/users/beliaev-maksim/orgs",
"repos_url": "https://api.github.com/users/beliaev-maksim/repos",
"events_url": "https://api.github.com/users/beliaev-maksim/events{/privacy}",
"received_events_url": "https://api.github.com/users/beliaev-maksim/received_events",
"type": "User",
"site_admin": false
},
"labels": [
{
"id": 5157325446,
"node_id": "LA_kwDOI-HsRM8AAAABM2aKhg",
"url": "https://api.github.com/repos/beliaev-maksim/test-ci/labels/bug",
"name": "bug",
"color": "d73a4a",
"default": true,
"description": "Something isn't working"
}
],
"state": "closed",
"locked": false,
"assignee": null,
"assignees": [

],
"milestone": null,
"comments": 1,
"created_at": "2024-08-14T14:40:44Z",
"updated_at": "2024-08-14T14:40:59Z",
"closed_at": "2024-08-14T14:40:58Z",
"author_association": "OWNER",
"active_lock_reason": null,
"body": null,
"reactions": {
"url": "https://api.github.com/repos/beliaev-maksim/test-ci/issues/30/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
},
"timeline_url": "https://api.github.com/repos/beliaev-maksim/test-ci/issues/30/timeline",
"performed_via_github_app": null,
"state_reason": "completed"
},
"repository": {
"id": 599027070,
"node_id": "R_kgDOI7Rtfg",
"name": "test-ci",
"full_name": "beliaev-maksim/test-ci",
"private": false,
"owner": {
"login": "beliaev-maksim",
"id": 51964909,
"node_id": "MDQ6VXNlcjUxOTY0OTA5",
"avatar_url": "https://avatars.githubusercontent.com/u/51964909?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/beliaev-maksim",
"html_url": "https://github.com/beliaev-maksim",
"followers_url": "https://api.github.com/users/beliaev-maksim/followers",
"following_url": "https://api.github.com/users/beliaev-maksim/following{/other_user}",
"gists_url": "https://api.github.com/users/beliaev-maksim/gists{/gist_id}",
"starred_url": "https://api.github.com/users/beliaev-maksim/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/beliaev-maksim/subscriptions",
"organizations_url": "https://api.github.com/users/beliaev-maksim/orgs",
"repos_url": "https://api.github.com/users/beliaev-maksim/repos",
"events_url": "https://api.github.com/users/beliaev-maksim/events{/privacy}",
"received_events_url": "https://api.github.com/users/beliaev-maksim/received_events",
"type": "User",
"site_admin": false
},
"html_url": "https://github.com/beliaev-maksim/test-ci",
"description": "Tools and tests for managing the Charmed Kubeflow bundle ",
"fork": true,
"url": "https://api.github.com/repos/beliaev-maksim/test-ci",
"forks_url": "https://api.github.com/repos/beliaev-maksim/test-ci/forks",
"keys_url": "https://api.github.com/repos/beliaev-maksim/test-ci/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/beliaev-maksim/test-ci/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/beliaev-maksim/test-ci/teams",
"hooks_url": "https://api.github.com/repos/beliaev-maksim/test-ci/hooks",
"issue_events_url": "https://api.github.com/repos/beliaev-maksim/test-ci/issues/events{/number}",
"events_url": "https://api.github.com/repos/beliaev-maksim/test-ci/events",
"assignees_url": "https://api.github.com/repos/beliaev-maksim/test-ci/assignees{/user}",
"branches_url": "https://api.github.com/repos/beliaev-maksim/test-ci/branches{/branch}",
"tags_url": "https://api.github.com/repos/beliaev-maksim/test-ci/tags",
"blobs_url": "https://api.github.com/repos/beliaev-maksim/test-ci/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/beliaev-maksim/test-ci/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/beliaev-maksim/test-ci/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/beliaev-maksim/test-ci/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/beliaev-maksim/test-ci/statuses/{sha}",
"languages_url": "https://api.github.com/repos/beliaev-maksim/test-ci/languages",
"stargazers_url": "https://api.github.com/repos/beliaev-maksim/test-ci/stargazers",
"contributors_url": "https://api.github.com/repos/beliaev-maksim/test-ci/contributors",
"subscribers_url": "https://api.github.com/repos/beliaev-maksim/test-ci/subscribers",
"subscription_url": "https://api.github.com/repos/beliaev-maksim/test-ci/subscription",
"commits_url": "https://api.github.com/repos/beliaev-maksim/test-ci/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/beliaev-maksim/test-ci/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/beliaev-maksim/test-ci/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/beliaev-maksim/test-ci/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/beliaev-maksim/test-ci/contents/{+path}",
"compare_url": "https://api.github.com/repos/beliaev-maksim/test-ci/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/beliaev-maksim/test-ci/merges",
"archive_url": "https://api.github.com/repos/beliaev-maksim/test-ci/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/beliaev-maksim/test-ci/downloads",
"issues_url": "https://api.github.com/repos/beliaev-maksim/test-ci/issues{/number}",
"pulls_url": "https://api.github.com/repos/beliaev-maksim/test-ci/pulls{/number}",
"milestones_url": "https://api.github.com/repos/beliaev-maksim/test-ci/milestones{/number}",
"notifications_url": "https://api.github.com/repos/beliaev-maksim/test-ci/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/beliaev-maksim/test-ci/labels{/name}",
"releases_url": "https://api.github.com/repos/beliaev-maksim/test-ci/releases{/id}",
"deployments_url": "https://api.github.com/repos/beliaev-maksim/test-ci/deployments",
"created_at": "2023-02-08T09:51:26Z",
"updated_at": "2024-08-14T14:40:34Z",
"pushed_at": "2023-03-15T20:39:44Z",
"git_url": "git://github.com/beliaev-maksim/test-ci.git",
"ssh_url": "[email protected]:beliaev-maksim/test-ci.git",
"clone_url": "https://github.com/beliaev-maksim/test-ci.git",
"svn_url": "https://github.com/beliaev-maksim/test-ci",
"homepage": "",
"size": 112,
"stargazers_count": 0,
"watchers_count": 0,
"language": null,
"has_issues": true,
"has_projects": true,
"has_downloads": true,
"has_wiki": false,
"has_pages": false,
"has_discussions": false,
"forks_count": 0,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 0,
"license": {
"key": "apache-2.0",
"name": "Apache License 2.0",
"spdx_id": "Apache-2.0",
"url": "https://api.github.com/licenses/apache-2.0",
"node_id": "MDc6TGljZW5zZTI="
},
"allow_forking": true,
"is_template": false,
"web_commit_signoff_required": false,
"topics": [

],
"visibility": "public",
"forks": 0,
"open_issues": 0,
"watchers": 0,
"default_branch": "main"
},
"sender": {
"login": "beliaev-maksim",
"id": 51964909,
"node_id": "MDQ6VXNlcjUxOTY0OTA5",
"avatar_url": "https://avatars.githubusercontent.com/u/51964909?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/beliaev-maksim",
"html_url": "https://github.com/beliaev-maksim",
"followers_url": "https://api.github.com/users/beliaev-maksim/followers",
"following_url": "https://api.github.com/users/beliaev-maksim/following{/other_user}",
"gists_url": "https://api.github.com/users/beliaev-maksim/gists{/gist_id}",
"starred_url": "https://api.github.com/users/beliaev-maksim/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/beliaev-maksim/subscriptions",
"organizations_url": "https://api.github.com/users/beliaev-maksim/orgs",
"repos_url": "https://api.github.com/users/beliaev-maksim/repos",
"events_url": "https://api.github.com/users/beliaev-maksim/events{/privacy}",
"received_events_url": "https://api.github.com/users/beliaev-maksim/received_events",
"type": "User",
"site_admin": false
},
"installation": {
"id": 42979996,
"node_id": "MDIzOkludGVncmF0aW9uSW5zdGFsbGF0aW9uNDI5Nzk5OTY="
}
}
Loading

0 comments on commit 0f252f4

Please sign in to comment.