Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New option for adding Synced label to GitHub issues after sync with Jira #59

Merged

Conversation

lorenzo-medici
Copy link
Contributor

Added two settings parameters add_gh_synced_label and gh_synced_label_name.

When the first one is true, a label with the name gh_synced_label_name will be added to newly created GitHub issues, if it already exists in the repo. Otherwise, nothing will be done on the issue.

If add_gh_comment is also true, comments will still be added to the GitHub issue together with the label, and if the synced label feature is misconfigured, a warning will be appended to it.

Closes #51

Copy link
Member

@beliaev-maksim beliaev-maksim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the PR

I think we can make the PR more lightweight and make the label name static

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
github_jira_sync_app/main.py Outdated Show resolved Hide resolved
@lorenzo-medici lorenzo-medici force-pushed the add_synced_label_to_gh_issue branch from bc7a7b2 to 01e235f Compare December 17, 2024 15:30
@lorenzo-medici
Copy link
Contributor Author

Applied both suggestions and signed commits.

@beliaev-maksim
Copy link
Member

also,
can you please add one line into architecture.md ?

App->>repo: (Optional) Adds a comment on the Issue

App->>repo: (Optional) Adds 'synced-to-jira' on the Issue 

tests/unit/dumm_env Outdated Show resolved Hide resolved
@lorenzo-medici lorenzo-medici force-pushed the add_synced_label_to_gh_issue branch from 01e235f to bee4e48 Compare December 18, 2024 14:20
@beliaev-maksim
Copy link
Member

@lorenzo-medici can you please fix the unittests?
or do you need some input from me before?

@lorenzo-medici
Copy link
Contributor Author

The test that is not passing needs a realistic body for adding a non existent label to be placed in tests/unit/url_responses/github_responses_synced_label_notfound.yaml

@lorenzo-medici
Copy link
Contributor Author

@beliaev-maksim I realized you might not have gotten the notification from the previous comment depending on your settings. (If you have, I apologize for spamming)

The test that is not passing needs a realistic body for adding a non existent label to be placed in tests/unit/url_responses/github_responses_synced_label_notfound.yaml

@beliaev-maksim
Copy link
Member

beliaev-maksim commented Dec 19, 2024

another thing that I discovered while debugging. When we apply label, it sends another webhook which adds unnecessary load on the server. Can we validate that this is caused by our label and ignore it?

here is the payload example

Details

{
    "action": "labeled",
    "issue": {
        "url": "https://api.github.com/repos/beliaev-maksim/test-ci/issues/6",
        "repository_url": "https://api.github.com/repos/beliaev-maksim/test-ci",
        "labels_url": "https://api.github.com/repos/beliaev-maksim/test-ci/issues/6/labels{/name}",
        "comments_url": "https://api.github.com/repos/beliaev-maksim/test-ci/issues/6/comments",
        "events_url": "https://api.github.com/repos/beliaev-maksim/test-ci/issues/6/events",
        "html_url": "https://github.com/beliaev-maksim/test-ci/issues/6",
        "id": 2749886114,
        "node_id": "I_kwDONftXdM6j5-6i",
        "number": 6,
        "title": "6",
        "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", "user_view_type": "public", "site_admin": false
        }
        ,
        "labels": [ {
            "id": 7904220484, "node_id": "LA_kwDONftXdM8AAAAB1yDVRA", "url": "https://api.github.com/repos/beliaev-maksim/test-ci/labels/synced-to-jira", "name": "synced-to-jira", "color": "ededed", "default": false, "description": null
        }
        ],
        "state": "open",
        "locked": false,
        "assignee": null,
        "assignees": [],
        "milestone": null,
        "comments": 0,
        "created_at": "2024-12-19T10:35:22Z",
        "updated_at": "2024-12-19T10:35:47Z",
        "closed_at": null,
        "author_association": "OWNER",
        "active_lock_reason": null,
        "body": null,
        "reactions": {
            "url": "https://api.github.com/repos/beliaev-maksim/test-ci/issues/6/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/6/timeline",
        "performed_via_github_app": null,
        "state_reason": null
    }
    ,
    "label": {
        "id": 7904220484, "node_id": "LA_kwDONftXdM8AAAAB1yDVRA", "url": "https://api.github.com/repos/beliaev-maksim/test-ci/labels/synced-to-jira", "name": "synced-to-jira", "color": "ededed", "default": false, "description": null
    }
    ,
    "repository": {
        "id": 905664372,
        "node_id": "R_kgDONftXdA",
        "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", "user_view_type": "public", "site_admin": false
        }
        ,
        "html_url": "https://github.com/beliaev-maksim/test-ci",
        "description": null,
        "fork": false,
        "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": "2024-12-19T09:29:31Z",
        "updated_at": "2024-12-19T09:34:32Z",
        "pushed_at": "2024-12-19T09:30:36Z",
        "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": null,
        "size": 1,
        "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": 6,
        "license": null,
        "allow_forking": true,
        "is_template": false,
        "web_commit_signoff_required": false,
        "topics": [],
        "visibility": "public",
        "forks": 0,
        "open_issues": 6,
        "watchers": 0,
        "default_branch": "master"
    }
    ,
    "sender": {
        "login": "test-payload-17-10-2023[bot]",
        "id": 148206313,
        "node_id": "BOT_kgDOCNVy6Q",
        "avatar_url": "https://avatars.githubusercontent.com/u/51964909?v=4",
        "gravatar_id": "",
        "url": "https://api.github.com/users/test-payload-17-10-2023%5Bbot%5D",
        "html_url": "https://github.com/apps/test-payload-17-10-2023",
        "followers_url": "https://api.github.com/users/test-payload-17-10-2023%5Bbot%5D/followers",
        "following_url": "https://api.github.com/users/test-payload-17-10-2023%5Bbot%5D/following{/other_user}",
        "gists_url": "https://api.github.com/users/test-payload-17-10-2023%5Bbot%5D/gists{/gist_id}",
        "starred_url": "https://api.github.com/users/test-payload-17-10-2023%5Bbot%5D/starred{/owner}{/repo}",
        "subscriptions_url": "https://api.github.com/users/test-payload-17-10-2023%5Bbot%5D/subscriptions",
        "organizations_url": "https://api.github.com/users/test-payload-17-10-2023%5Bbot%5D/orgs",
        "repos_url": "https://api.github.com/users/test-payload-17-10-2023%5Bbot%5D/repos",
        "events_url": "https://api.github.com/users/test-payload-17-10-2023%5Bbot%5D/events{/privacy}",
        "received_events_url": "https://api.github.com/users/test-payload-17-10-2023%5Bbot%5D/received_events", "type": "Bot", "user_view_type": "public", "site_admin": false
    }
    ,
    "installation": {
        "id": 42979996, "node_id": "MDIzOkludGVncmF0aW9uSW5zdGFsbGF0aW9uNDI5Nzk5OTY="
    }
}

@beliaev-maksim
Copy link
Member

here is the example of response with labels. It looks like label is created if label does not exist. Can you check the docs?

Details

- response:
    auto_calculate_content_length: false
    body: '[{"id":7904251331,"node_id":"LA_kwDONftXdM8AAAAB1yFNww","url":"https://api.github.com/repos/beliaev-maksim/test-ci/labels/synced-to-jira","name":"synced-to-jira","color":"ededed","default":false,"description":null}]'
    content_type: text/plain
    headers:
      Access-Control-Allow-Origin: '*'
      Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP,
        X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource,
        X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval,
        X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset
      Cache-Control: private, max-age=60, s-maxage=60
      Content-Security-Policy: default-src 'none'
      ETag: W/"27d4a15dae729ce6fc531eeddd17d6834055ee847c6ea86d9ecbf1c1818363fd"
      Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
      Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
      Transfer-Encoding: chunked
      Vary: Accept, Authorization, Cookie, X-GitHub-OTP,Accept-Encoding, Accept, X-Requested-With
      X-Content-Type-Options: nosniff
      X-Frame-Options: deny
      X-GitHub-Media-Type: github.v3; format=json
      X-GitHub-Request-Id: 66A2:AD2C0:2ADEB5D:2BCC1E4:6763F8F3
      X-RateLimit-Limit: '7950'
      X-RateLimit-Remaining: '7941'
      X-RateLimit-Reset: '1734608131'
      X-RateLimit-Resource: core
      X-RateLimit-Used: '9'
      X-XSS-Protection: '0'
      x-accepted-github-permissions: issues=write; pull_requests=write
      x-github-api-version-selected: '2022-11-28'
    method: POST
    status: 200
    url: https://api.github.com:443/repos/beliaev-maksim/test-ci/issues/8/labels

@lorenzo-medici
Copy link
Contributor Author

@beliaev-maksim there is nothing in the docs (at least the ones I found here) that says that a label will be created if it doesn't exist, and the add_to_labels function is a simple wrapper for the POST request.

Is the webhook you mentioned in the bot server or on the GitHub server? If it is the latter it might be creating the label automatically in the background, in which case we should just remove the ŧry block around add_to_labels and the warning comments as the label will always be created if it doesn't exist.

@beliaev-maksim
Copy link
Member

If it is the latter it might be creating the label automatically in the background, in which case we should just remove the ŧry block around add_to_labels and the warning comments as the label will always be created if it doesn't exist.

it looks like we can remove try block and we can remove the comment then, that it cannot add a label.

@beliaev-maksim
Copy link
Member

another thing that I discovered while debugging. When we apply label, it sends another webhook which adds unnecessary load on the server. Can we validate that this is caused by our label and ignore it?

this one is a separate issue. As soon as we label, it is another event that GH will send to our server

@lorenzo-medici lorenzo-medici force-pushed the add_synced_label_to_gh_issue branch from bee4e48 to 22ad5e0 Compare December 19, 2024 15:43
@lorenzo-medici
Copy link
Contributor Author

@beliaev-maksim Handled both issues in the two latest commits.
For the extra webhook I added a check for payload["action"] == "labeled" and payload["label"]["name"] == gh_synced_label_name to return early when filtering for the types of actions.
I unified the test cases since the payload and response were identical, and the test also checks for inaction on the second webhook.

@beliaev-maksim
Copy link
Member

opened GH doc issue
github/docs#35718

I just tested with cURL and got two labels created

Copy link
Member

@beliaev-maksim beliaev-maksim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is a high quality work, thank you!

@beliaev-maksim beliaev-maksim merged commit 1614ff2 into canonical:main Dec 19, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

apply label "synced" for issues that were syncronysed
2 participants