From 45898561705c007f46ed2e5963292bf9886622ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Z=C3=B8rn?= Date: Mon, 29 Apr 2024 17:35:53 +0200 Subject: [PATCH 1/5] feat(everything): Refactoring the way events are read to enable multiple event types --- event.yaml | 505 ++++++++++++++++++ .../com/monta/slack/notifier/SlackClient.kt | 82 ++- .../notifier/command/PublishSlackCommand.kt | 35 +- .../monta/slack/notifier/model/GithubEvent.kt | 24 + .../slack/notifier/model/GithubPushContext.kt | 149 ------ .../model/GithubTrunkBasedPushContext.kt | 41 -- .../model/serializers/BaseGithubContext.kt | 9 + .../model/serializers/GithubCreatedContext.kt | 21 + .../model/serializers/GithubOpenedContext.kt | 24 + .../model/serializers/GithubPushContext.kt | 78 +++ .../notifier/service/PublishSlackService.kt | 8 +- .../monta/slack/notifier/util/FileUtils.kt | 65 +++ .../monta/slack/notifier/util/TrunkUtils.kt | 20 - 13 files changed, 822 insertions(+), 239 deletions(-) create mode 100644 event.yaml create mode 100644 src/commonMain/kotlin/com/monta/slack/notifier/model/GithubEvent.kt delete mode 100644 src/commonMain/kotlin/com/monta/slack/notifier/model/GithubPushContext.kt delete mode 100644 src/commonMain/kotlin/com/monta/slack/notifier/model/GithubTrunkBasedPushContext.kt create mode 100644 src/commonMain/kotlin/com/monta/slack/notifier/model/serializers/BaseGithubContext.kt create mode 100644 src/commonMain/kotlin/com/monta/slack/notifier/model/serializers/GithubCreatedContext.kt create mode 100644 src/commonMain/kotlin/com/monta/slack/notifier/model/serializers/GithubOpenedContext.kt create mode 100644 src/commonMain/kotlin/com/monta/slack/notifier/model/serializers/GithubPushContext.kt delete mode 100644 src/commonMain/kotlin/com/monta/slack/notifier/util/TrunkUtils.kt diff --git a/event.yaml b/event.yaml new file mode 100644 index 0000000..7a5a750 --- /dev/null +++ b/event.yaml @@ -0,0 +1,505 @@ +{ + "action": "synchronize", + "after": "06113c1af18885efc43e8ce60f94cd79f651a71f", + "before": "09f10a7de2ff88f2e81497d3429f062b482ea4e9", + "number": 49, + "organization": { + "avatar_url": "https://avatars.githubusercontent.com/u/70286931?v=4", + "description": "EV Better", + "events_url": "https://api.github.com/orgs/monta-app/events", + "hooks_url": "https://api.github.com/orgs/monta-app/hooks", + "id": 70286931, + "issues_url": "https://api.github.com/orgs/monta-app/issues", + "login": "monta-app", + "members_url": "https://api.github.com/orgs/monta-app/members{/member}", + "node_id": "MDEyOk9yZ2FuaXphdGlvbjcwMjg2OTMx", + "public_members_url": "https://api.github.com/orgs/monta-app/public_members{/member}", + "repos_url": "https://api.github.com/orgs/monta-app/repos", + "url": "https://api.github.com/orgs/monta-app" + }, + "pull_request": { + "_links": { + "comments": { + "href": "https://api.github.com/repos/monta-app/data-smart-charge/issues/49/comments" + }, + "commits": { + "href": "https://api.github.com/repos/monta-app/data-smart-charge/pulls/49/commits" + }, + "html": { + "href": "https://github.com/monta-app/data-smart-charge/pull/49" + }, + "issue": { + "href": "https://api.github.com/repos/monta-app/data-smart-charge/issues/49" + }, + "review_comment": { + "href": "https://api.github.com/repos/monta-app/data-smart-charge/pulls/comments{/number}" + }, + "review_comments": { + "href": "https://api.github.com/repos/monta-app/data-smart-charge/pulls/49/comments" + }, + "self": { + "href": "https://api.github.com/repos/monta-app/data-smart-charge/pulls/49" + }, + "statuses": { + "href": "https://api.github.com/repos/monta-app/data-smart-charge/statuses/06113c1af18885efc43e8ce60f94cd79f651a71f" + } + }, + "active_lock_reason": null, + "additions": 6, + "assignee": null, + "assignees": [], + "author_association": "CONTRIBUTOR", + "auto_merge": null, + "base": { + "label": "monta-app:main", + "ref": "main", + "repo": { + "allow_auto_merge": false, + "allow_forking": false, + "allow_merge_commit": true, + "allow_rebase_merge": true, + "allow_squash_merge": true, + "allow_update_branch": false, + "archive_url": "https://api.github.com/repos/monta-app/data-smart-charge/{archive_format}{/ref}", + "archived": false, + "assignees_url": "https://api.github.com/repos/monta-app/data-smart-charge/assignees{/user}", + "blobs_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/blobs{/sha}", + "branches_url": "https://api.github.com/repos/monta-app/data-smart-charge/branches{/branch}", + "clone_url": "https://github.com/monta-app/data-smart-charge.git", + "collaborators_url": "https://api.github.com/repos/monta-app/data-smart-charge/collaborators{/collaborator}", + "comments_url": "https://api.github.com/repos/monta-app/data-smart-charge/comments{/number}", + "commits_url": "https://api.github.com/repos/monta-app/data-smart-charge/commits{/sha}", + "compare_url": "https://api.github.com/repos/monta-app/data-smart-charge/compare/{base}...{head}", + "contents_url": "https://api.github.com/repos/monta-app/data-smart-charge/contents/{+path}", + "contributors_url": "https://api.github.com/repos/monta-app/data-smart-charge/contributors", + "created_at": "2024-02-09T13:53:23Z", + "default_branch": "main", + "delete_branch_on_merge": false, + "deployments_url": "https://api.github.com/repos/monta-app/data-smart-charge/deployments", + "description": "Smart charge service", + "disabled": false, + "downloads_url": "https://api.github.com/repos/monta-app/data-smart-charge/downloads", + "events_url": "https://api.github.com/repos/monta-app/data-smart-charge/events", + "fork": false, + "forks": 0, + "forks_count": 0, + "forks_url": "https://api.github.com/repos/monta-app/data-smart-charge/forks", + "full_name": "monta-app/data-smart-charge", + "git_commits_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/commits{/sha}", + "git_refs_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/refs{/sha}", + "git_tags_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/tags{/sha}", + "git_url": "git://github.com/monta-app/data-smart-charge.git", + "has_discussions": false, + "has_downloads": true, + "has_issues": true, + "has_pages": false, + "has_projects": true, + "has_wiki": true, + "homepage": "", + "hooks_url": "https://api.github.com/repos/monta-app/data-smart-charge/hooks", + "html_url": "https://github.com/monta-app/data-smart-charge", + "id": 755136543, + "is_template": false, + "issue_comment_url": "https://api.github.com/repos/monta-app/data-smart-charge/issues/comments{/number}", + "issue_events_url": "https://api.github.com/repos/monta-app/data-smart-charge/issues/events{/number}", + "issues_url": "https://api.github.com/repos/monta-app/data-smart-charge/issues{/number}", + "keys_url": "https://api.github.com/repos/monta-app/data-smart-charge/keys{/key_id}", + "labels_url": "https://api.github.com/repos/monta-app/data-smart-charge/labels{/name}", + "language": "Python", + "languages_url": "https://api.github.com/repos/monta-app/data-smart-charge/languages", + "license": null, + "merge_commit_message": "PR_TITLE", + "merge_commit_title": "MERGE_MESSAGE", + "merges_url": "https://api.github.com/repos/monta-app/data-smart-charge/merges", + "milestones_url": "https://api.github.com/repos/monta-app/data-smart-charge/milestones{/number}", + "mirror_url": null, + "name": "data-smart-charge", + "node_id": "R_kgDOLQJ4Hw", + "notifications_url": "https://api.github.com/repos/monta-app/data-smart-charge/notifications{?since,all,participating}", + "open_issues": 7, + "open_issues_count": 7, + "owner": { + "avatar_url": "https://avatars.githubusercontent.com/u/70286931?v=4", + "events_url": "https://api.github.com/users/monta-app/events{/privacy}", + "followers_url": "https://api.github.com/users/monta-app/followers", + "following_url": "https://api.github.com/users/monta-app/following{/other_user}", + "gists_url": "https://api.github.com/users/monta-app/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/monta-app", + "id": 70286931, + "login": "monta-app", + "node_id": "MDEyOk9yZ2FuaXphdGlvbjcwMjg2OTMx", + "organizations_url": "https://api.github.com/users/monta-app/orgs", + "received_events_url": "https://api.github.com/users/monta-app/received_events", + "repos_url": "https://api.github.com/users/monta-app/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/monta-app/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/monta-app/subscriptions", + "type": "Organization", + "url": "https://api.github.com/users/monta-app" + }, + "private": true, + "pulls_url": "https://api.github.com/repos/monta-app/data-smart-charge/pulls{/number}", + "pushed_at": "2024-04-26T10:35:29Z", + "releases_url": "https://api.github.com/repos/monta-app/data-smart-charge/releases{/id}", + "size": 733, + "squash_merge_commit_message": "COMMIT_MESSAGES", + "squash_merge_commit_title": "COMMIT_OR_PR_TITLE", + "ssh_url": "git@github.com:monta-app/data-smart-charge.git", + "stargazers_count": 1, + "stargazers_url": "https://api.github.com/repos/monta-app/data-smart-charge/stargazers", + "statuses_url": "https://api.github.com/repos/monta-app/data-smart-charge/statuses/{sha}", + "subscribers_url": "https://api.github.com/repos/monta-app/data-smart-charge/subscribers", + "subscription_url": "https://api.github.com/repos/monta-app/data-smart-charge/subscription", + "svn_url": "https://github.com/monta-app/data-smart-charge", + "tags_url": "https://api.github.com/repos/monta-app/data-smart-charge/tags", + "teams_url": "https://api.github.com/repos/monta-app/data-smart-charge/teams", + "topics": [], + "trees_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/trees{/sha}", + "updated_at": "2024-04-26T10:20:57Z", + "url": "https://api.github.com/repos/monta-app/data-smart-charge", + "use_squash_pr_title_as_default": false, + "visibility": "private", + "watchers": 1, + "watchers_count": 1, + "web_commit_signoff_required": false + }, + "sha": "673ac883ed63a26806babac4b6deb24307f37cdc", + "user": { + "avatar_url": "https://avatars.githubusercontent.com/u/70286931?v=4", + "events_url": "https://api.github.com/users/monta-app/events{/privacy}", + "followers_url": "https://api.github.com/users/monta-app/followers", + "following_url": "https://api.github.com/users/monta-app/following{/other_user}", + "gists_url": "https://api.github.com/users/monta-app/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/monta-app", + "id": 70286931, + "login": "monta-app", + "node_id": "MDEyOk9yZ2FuaXphdGlvbjcwMjg2OTMx", + "organizations_url": "https://api.github.com/users/monta-app/orgs", + "received_events_url": "https://api.github.com/users/monta-app/received_events", + "repos_url": "https://api.github.com/users/monta-app/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/monta-app/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/monta-app/subscriptions", + "type": "Organization", + "url": "https://api.github.com/users/monta-app" + } + }, + "body": null, + "changed_files": 2, + "closed_at": null, + "comments": 1, + "comments_url": "https://api.github.com/repos/monta-app/data-smart-charge/issues/49/comments", + "commits": 2, + "commits_url": "https://api.github.com/repos/monta-app/data-smart-charge/pulls/49/commits", + "created_at": "2024-04-26T10:34:20Z", + "deletions": 6, + "diff_url": "https://github.com/monta-app/data-smart-charge/pull/49.diff", + "draft": false, + "head": { + "label": "monta-app:fix/revert-slack-notif-cli-version", + "ref": "fix/revert-slack-notif-cli-version", + "repo": { + "allow_auto_merge": false, + "allow_forking": false, + "allow_merge_commit": true, + "allow_rebase_merge": true, + "allow_squash_merge": true, + "allow_update_branch": false, + "archive_url": "https://api.github.com/repos/monta-app/data-smart-charge/{archive_format}{/ref}", + "archived": false, + "assignees_url": "https://api.github.com/repos/monta-app/data-smart-charge/assignees{/user}", + "blobs_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/blobs{/sha}", + "branches_url": "https://api.github.com/repos/monta-app/data-smart-charge/branches{/branch}", + "clone_url": "https://github.com/monta-app/data-smart-charge.git", + "collaborators_url": "https://api.github.com/repos/monta-app/data-smart-charge/collaborators{/collaborator}", + "comments_url": "https://api.github.com/repos/monta-app/data-smart-charge/comments{/number}", + "commits_url": "https://api.github.com/repos/monta-app/data-smart-charge/commits{/sha}", + "compare_url": "https://api.github.com/repos/monta-app/data-smart-charge/compare/{base}...{head}", + "contents_url": "https://api.github.com/repos/monta-app/data-smart-charge/contents/{+path}", + "contributors_url": "https://api.github.com/repos/monta-app/data-smart-charge/contributors", + "created_at": "2024-02-09T13:53:23Z", + "default_branch": "main", + "delete_branch_on_merge": false, + "deployments_url": "https://api.github.com/repos/monta-app/data-smart-charge/deployments", + "description": "Smart charge service", + "disabled": false, + "downloads_url": "https://api.github.com/repos/monta-app/data-smart-charge/downloads", + "events_url": "https://api.github.com/repos/monta-app/data-smart-charge/events", + "fork": false, + "forks": 0, + "forks_count": 0, + "forks_url": "https://api.github.com/repos/monta-app/data-smart-charge/forks", + "full_name": "monta-app/data-smart-charge", + "git_commits_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/commits{/sha}", + "git_refs_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/refs{/sha}", + "git_tags_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/tags{/sha}", + "git_url": "git://github.com/monta-app/data-smart-charge.git", + "has_discussions": false, + "has_downloads": true, + "has_issues": true, + "has_pages": false, + "has_projects": true, + "has_wiki": true, + "homepage": "", + "hooks_url": "https://api.github.com/repos/monta-app/data-smart-charge/hooks", + "html_url": "https://github.com/monta-app/data-smart-charge", + "id": 755136543, + "is_template": false, + "issue_comment_url": "https://api.github.com/repos/monta-app/data-smart-charge/issues/comments{/number}", + "issue_events_url": "https://api.github.com/repos/monta-app/data-smart-charge/issues/events{/number}", + "issues_url": "https://api.github.com/repos/monta-app/data-smart-charge/issues{/number}", + "keys_url": "https://api.github.com/repos/monta-app/data-smart-charge/keys{/key_id}", + "labels_url": "https://api.github.com/repos/monta-app/data-smart-charge/labels{/name}", + "language": "Python", + "languages_url": "https://api.github.com/repos/monta-app/data-smart-charge/languages", + "license": null, + "merge_commit_message": "PR_TITLE", + "merge_commit_title": "MERGE_MESSAGE", + "merges_url": "https://api.github.com/repos/monta-app/data-smart-charge/merges", + "milestones_url": "https://api.github.com/repos/monta-app/data-smart-charge/milestones{/number}", + "mirror_url": null, + "name": "data-smart-charge", + "node_id": "R_kgDOLQJ4Hw", + "notifications_url": "https://api.github.com/repos/monta-app/data-smart-charge/notifications{?since,all,participating}", + "open_issues": 7, + "open_issues_count": 7, + "owner": { + "avatar_url": "https://avatars.githubusercontent.com/u/70286931?v=4", + "events_url": "https://api.github.com/users/monta-app/events{/privacy}", + "followers_url": "https://api.github.com/users/monta-app/followers", + "following_url": "https://api.github.com/users/monta-app/following{/other_user}", + "gists_url": "https://api.github.com/users/monta-app/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/monta-app", + "id": 70286931, + "login": "monta-app", + "node_id": "MDEyOk9yZ2FuaXphdGlvbjcwMjg2OTMx", + "organizations_url": "https://api.github.com/users/monta-app/orgs", + "received_events_url": "https://api.github.com/users/monta-app/received_events", + "repos_url": "https://api.github.com/users/monta-app/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/monta-app/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/monta-app/subscriptions", + "type": "Organization", + "url": "https://api.github.com/users/monta-app" + }, + "private": true, + "pulls_url": "https://api.github.com/repos/monta-app/data-smart-charge/pulls{/number}", + "pushed_at": "2024-04-26T10:35:29Z", + "releases_url": "https://api.github.com/repos/monta-app/data-smart-charge/releases{/id}", + "size": 733, + "squash_merge_commit_message": "COMMIT_MESSAGES", + "squash_merge_commit_title": "COMMIT_OR_PR_TITLE", + "ssh_url": "git@github.com:monta-app/data-smart-charge.git", + "stargazers_count": 1, + "stargazers_url": "https://api.github.com/repos/monta-app/data-smart-charge/stargazers", + "statuses_url": "https://api.github.com/repos/monta-app/data-smart-charge/statuses/{sha}", + "subscribers_url": "https://api.github.com/repos/monta-app/data-smart-charge/subscribers", + "subscription_url": "https://api.github.com/repos/monta-app/data-smart-charge/subscription", + "svn_url": "https://github.com/monta-app/data-smart-charge", + "tags_url": "https://api.github.com/repos/monta-app/data-smart-charge/tags", + "teams_url": "https://api.github.com/repos/monta-app/data-smart-charge/teams", + "topics": [], + "trees_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/trees{/sha}", + "updated_at": "2024-04-26T10:20:57Z", + "url": "https://api.github.com/repos/monta-app/data-smart-charge", + "use_squash_pr_title_as_default": false, + "visibility": "private", + "watchers": 1, + "watchers_count": 1, + "web_commit_signoff_required": false + }, + "sha": "06113c1af18885efc43e8ce60f94cd79f651a71f", + "user": { + "avatar_url": "https://avatars.githubusercontent.com/u/70286931?v=4", + "events_url": "https://api.github.com/users/monta-app/events{/privacy}", + "followers_url": "https://api.github.com/users/monta-app/followers", + "following_url": "https://api.github.com/users/monta-app/following{/other_user}", + "gists_url": "https://api.github.com/users/monta-app/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/monta-app", + "id": 70286931, + "login": "monta-app", + "node_id": "MDEyOk9yZ2FuaXphdGlvbjcwMjg2OTMx", + "organizations_url": "https://api.github.com/users/monta-app/orgs", + "received_events_url": "https://api.github.com/users/monta-app/received_events", + "repos_url": "https://api.github.com/users/monta-app/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/monta-app/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/monta-app/subscriptions", + "type": "Organization", + "url": "https://api.github.com/users/monta-app" + } + }, + "html_url": "https://github.com/monta-app/data-smart-charge/pull/49", + "id": 1842600504, + "issue_url": "https://api.github.com/repos/monta-app/data-smart-charge/issues/49", + "labels": [], + "locked": false, + "maintainer_can_modify": false, + "merge_commit_sha": "a9490f607c5c4dfc713e0dea5067ba9d49c384a6", + "mergeable": null, + "mergeable_state": "unknown", + "merged": false, + "merged_at": null, + "merged_by": null, + "milestone": null, + "node_id": "PR_kwDOLQJ4H85t09o4", + "number": 49, + "patch_url": "https://github.com/monta-app/data-smart-charge/pull/49.patch", + "rebaseable": null, + "requested_reviewers": [], + "requested_teams": [], + "review_comment_url": "https://api.github.com/repos/monta-app/data-smart-charge/pulls/comments{/number}", + "review_comments": 0, + "review_comments_url": "https://api.github.com/repos/monta-app/data-smart-charge/pulls/49/comments", + "state": "open", + "statuses_url": "https://api.github.com/repos/monta-app/data-smart-charge/statuses/06113c1af18885efc43e8ce60f94cd79f651a71f", + "title": "fix(workflow): revert to main version of slack notif cli", + "updated_at": "2024-04-26T10:35:30Z", + "url": "https://api.github.com/repos/monta-app/data-smart-charge/pulls/49", + "user": { + "avatar_url": "https://avatars.githubusercontent.com/u/63373006?v=4", + "events_url": "https://api.github.com/users/baldm/events{/privacy}", + "followers_url": "https://api.github.com/users/baldm/followers", + "following_url": "https://api.github.com/users/baldm/following{/other_user}", + "gists_url": "https://api.github.com/users/baldm/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/baldm", + "id": 63373006, + "login": "baldm", + "node_id": "MDQ6VXNlcjYzMzczMDA2", + "organizations_url": "https://api.github.com/users/baldm/orgs", + "received_events_url": "https://api.github.com/users/baldm/received_events", + "repos_url": "https://api.github.com/users/baldm/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/baldm/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/baldm/subscriptions", + "type": "User", + "url": "https://api.github.com/users/baldm" + } + }, + "repository": { + "allow_forking": false, + "archive_url": "https://api.github.com/repos/monta-app/data-smart-charge/{archive_format}{/ref}", + "archived": false, + "assignees_url": "https://api.github.com/repos/monta-app/data-smart-charge/assignees{/user}", + "blobs_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/blobs{/sha}", + "branches_url": "https://api.github.com/repos/monta-app/data-smart-charge/branches{/branch}", + "clone_url": "https://github.com/monta-app/data-smart-charge.git", + "collaborators_url": "https://api.github.com/repos/monta-app/data-smart-charge/collaborators{/collaborator}", + "comments_url": "https://api.github.com/repos/monta-app/data-smart-charge/comments{/number}", + "commits_url": "https://api.github.com/repos/monta-app/data-smart-charge/commits{/sha}", + "compare_url": "https://api.github.com/repos/monta-app/data-smart-charge/compare/{base}...{head}", + "contents_url": "https://api.github.com/repos/monta-app/data-smart-charge/contents/{+path}", + "contributors_url": "https://api.github.com/repos/monta-app/data-smart-charge/contributors", + "created_at": "2024-02-09T13:53:23Z", + "custom_properties": {}, + "default_branch": "main", + "deployments_url": "https://api.github.com/repos/monta-app/data-smart-charge/deployments", + "description": "Smart charge service", + "disabled": false, + "downloads_url": "https://api.github.com/repos/monta-app/data-smart-charge/downloads", + "events_url": "https://api.github.com/repos/monta-app/data-smart-charge/events", + "fork": false, + "forks": 0, + "forks_count": 0, + "forks_url": "https://api.github.com/repos/monta-app/data-smart-charge/forks", + "full_name": "monta-app/data-smart-charge", + "git_commits_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/commits{/sha}", + "git_refs_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/refs{/sha}", + "git_tags_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/tags{/sha}", + "git_url": "git://github.com/monta-app/data-smart-charge.git", + "has_discussions": false, + "has_downloads": true, + "has_issues": true, + "has_pages": false, + "has_projects": true, + "has_wiki": true, + "homepage": "", + "hooks_url": "https://api.github.com/repos/monta-app/data-smart-charge/hooks", + "html_url": "https://github.com/monta-app/data-smart-charge", + "id": 755136543, + "is_template": false, + "issue_comment_url": "https://api.github.com/repos/monta-app/data-smart-charge/issues/comments{/number}", + "issue_events_url": "https://api.github.com/repos/monta-app/data-smart-charge/issues/events{/number}", + "issues_url": "https://api.github.com/repos/monta-app/data-smart-charge/issues{/number}", + "keys_url": "https://api.github.com/repos/monta-app/data-smart-charge/keys{/key_id}", + "labels_url": "https://api.github.com/repos/monta-app/data-smart-charge/labels{/name}", + "language": "Python", + "languages_url": "https://api.github.com/repos/monta-app/data-smart-charge/languages", + "license": null, + "merges_url": "https://api.github.com/repos/monta-app/data-smart-charge/merges", + "milestones_url": "https://api.github.com/repos/monta-app/data-smart-charge/milestones{/number}", + "mirror_url": null, + "name": "data-smart-charge", + "node_id": "R_kgDOLQJ4Hw", + "notifications_url": "https://api.github.com/repos/monta-app/data-smart-charge/notifications{?since,all,participating}", + "open_issues": 7, + "open_issues_count": 7, + "owner": { + "avatar_url": "https://avatars.githubusercontent.com/u/70286931?v=4", + "events_url": "https://api.github.com/users/monta-app/events{/privacy}", + "followers_url": "https://api.github.com/users/monta-app/followers", + "following_url": "https://api.github.com/users/monta-app/following{/other_user}", + "gists_url": "https://api.github.com/users/monta-app/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/monta-app", + "id": 70286931, + "login": "monta-app", + "node_id": "MDEyOk9yZ2FuaXphdGlvbjcwMjg2OTMx", + "organizations_url": "https://api.github.com/users/monta-app/orgs", + "received_events_url": "https://api.github.com/users/monta-app/received_events", + "repos_url": "https://api.github.com/users/monta-app/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/monta-app/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/monta-app/subscriptions", + "type": "Organization", + "url": "https://api.github.com/users/monta-app" + }, + "private": true, + "pulls_url": "https://api.github.com/repos/monta-app/data-smart-charge/pulls{/number}", + "pushed_at": "2024-04-26T10:35:29Z", + "releases_url": "https://api.github.com/repos/monta-app/data-smart-charge/releases{/id}", + "size": 733, + "ssh_url": "git@github.com:monta-app/data-smart-charge.git", + "stargazers_count": 1, + "stargazers_url": "https://api.github.com/repos/monta-app/data-smart-charge/stargazers", + "statuses_url": "https://api.github.com/repos/monta-app/data-smart-charge/statuses/{sha}", + "subscribers_url": "https://api.github.com/repos/monta-app/data-smart-charge/subscribers", + "subscription_url": "https://api.github.com/repos/monta-app/data-smart-charge/subscription", + "svn_url": "https://github.com/monta-app/data-smart-charge", + "tags_url": "https://api.github.com/repos/monta-app/data-smart-charge/tags", + "teams_url": "https://api.github.com/repos/monta-app/data-smart-charge/teams", + "topics": [], + "trees_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/trees{/sha}", + "updated_at": "2024-04-26T10:20:57Z", + "url": "https://api.github.com/repos/monta-app/data-smart-charge", + "visibility": "private", + "watchers": 1, + "watchers_count": 1, + "web_commit_signoff_required": false + }, + "sender": { + "avatar_url": "https://avatars.githubusercontent.com/u/63373006?v=4", + "events_url": "https://api.github.com/users/baldm/events{/privacy}", + "followers_url": "https://api.github.com/users/baldm/followers", + "following_url": "https://api.github.com/users/baldm/following{/other_user}", + "gists_url": "https://api.github.com/users/baldm/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/baldm", + "id": 63373006, + "login": "baldm", + "node_id": "MDQ6VXNlcjYzMzczMDA2", + "organizations_url": "https://api.github.com/users/baldm/orgs", + "received_events_url": "https://api.github.com/users/baldm/received_events", + "repos_url": "https://api.github.com/users/baldm/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/baldm/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/baldm/subscriptions", + "type": "User", + "url": "https://api.github.com/users/baldm" + } +} diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/SlackClient.kt b/src/commonMain/kotlin/com/monta/slack/notifier/SlackClient.kt index 542e339..8b741ce 100644 --- a/src/commonMain/kotlin/com/monta/slack/notifier/SlackClient.kt +++ b/src/commonMain/kotlin/com/monta/slack/notifier/SlackClient.kt @@ -1,10 +1,12 @@ package com.monta.slack.notifier -import com.monta.slack.notifier.model.GithubPushContext +import com.monta.slack.notifier.model.GithubEvent import com.monta.slack.notifier.model.JobStatus import com.monta.slack.notifier.model.JobType +import com.monta.slack.notifier.model.SlackBlock import com.monta.slack.notifier.model.SlackMessage import com.monta.slack.notifier.util.JsonUtil +import com.monta.slack.notifier.util.buildTitle import com.monta.slack.notifier.util.client import io.ktor.client.request.* import io.ktor.client.statement.* @@ -21,14 +23,14 @@ class SlackClient( ) { suspend fun create( - githubPushContext: GithubPushContext, + githubEvent: GithubEvent, jobType: JobType, jobStatus: JobStatus, ): String { val response = makeSlackRequest( url = "https://slack.com/api/chat.postMessage", - message = generateMessage( - githubPushContext = githubPushContext, + message = generateMessageFromGithubEvent( + githubEvent = githubEvent, jobType = jobType, jobStatus = jobStatus ) @@ -39,7 +41,7 @@ class SlackClient( suspend fun update( messageId: String, - githubPushContext: GithubPushContext, + githubEvent: GithubEvent, jobType: JobType, jobStatus: JobStatus, ): String { @@ -47,8 +49,8 @@ class SlackClient( val response = makeSlackRequest( url = "https://slack.com/api/chat.update", - message = generateMessage( - githubPushContext = githubPushContext, + message = generateMessageFromGithubEvent( + githubEvent = githubEvent, jobType = jobType, jobStatus = jobStatus, messageId = messageId, @@ -59,8 +61,67 @@ class SlackClient( return requireNotNull(response?.ts) } - private fun generateMessage( - githubPushContext: GithubPushContext, + private fun generateSlackMessageFromEvent( + githubEvent: GithubEvent, + serviceName: String?, + serviceEmoji: String?, + slackChannelId: String, + messageId: String?, + attachments: List?, + ): SlackMessage { + + val title = buildTitle(githubEvent.repository, githubEvent.workflow, serviceName, serviceEmoji) + + return SlackMessage( + channel = slackChannelId, + ts = messageId, + text = title, + blocks = listOf( + SlackBlock( + type = "header", + text = SlackBlock.Text( + type = "plain_text", + text = title + ) + ), + SlackBlock( + type = "divider" + ), + SlackBlock( + type = "section", + fields = listOf( + SlackBlock.Text( + type = "mrkdwn", + text = " \n*Branch:*\n${githubEvent.refName}" + ), + SlackBlock.Text( + type = "mrkdwn", + text = " \n*Run:*\n<${githubEvent.getRunUrl()}|${githubEvent.runId}>" + ), + SlackBlock.Text( + type = "mrkdwn", + text = " \n*Comitter:*\n${githubEvent.displayName}" + ), + SlackBlock.Text( + type = "mrkdwn", + text = " \n*Message:*\n<${githubEvent.getCommitUrl()}|${githubEvent.getCommitMessage()}>" + ), + SlackBlock.Text( + type = "mrkdwn", + text = " \n*SHA:*\n<${githubEvent.getCommitUrl()}|${githubEvent.commitSHA}>" + ) + ) + ), + SlackBlock( + type = "divider" + ) + ), + attachments = attachments + ) + } + + private fun generateMessageFromGithubEvent( + githubEvent: GithubEvent, jobType: JobType, jobStatus: JobStatus, messageId: String? = null, @@ -86,7 +147,8 @@ class SlackClient( ) ) - return githubPushContext.toMessage( + return generateSlackMessageFromEvent( + githubEvent = githubEvent, serviceName = serviceName, serviceEmoji = serviceEmoji, slackChannelId = slackChannelId, diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/command/PublishSlackCommand.kt b/src/commonMain/kotlin/com/monta/slack/notifier/command/PublishSlackCommand.kt index 89a0cb8..8bf09e4 100644 --- a/src/commonMain/kotlin/com/monta/slack/notifier/command/PublishSlackCommand.kt +++ b/src/commonMain/kotlin/com/monta/slack/notifier/command/PublishSlackCommand.kt @@ -3,12 +3,14 @@ package com.monta.slack.notifier.command import com.github.ajalt.clikt.core.CliktCommand import com.github.ajalt.clikt.parameters.options.option import com.github.ajalt.clikt.parameters.options.required -import com.monta.slack.notifier.model.GithubPushContext +import com.monta.slack.notifier.model.GithubEvent +import com.monta.slack.notifier.model.serializers.GithubPushContext import com.monta.slack.notifier.model.JobStatus import com.monta.slack.notifier.model.JobType +import com.monta.slack.notifier.model.serializers.BaseGithubContext import com.monta.slack.notifier.service.PublishSlackService import com.monta.slack.notifier.util.JsonUtil -import com.monta.slack.notifier.util.populateEventFromTrunkBasedEvent +import com.monta.slack.notifier.util.populateEventFromJson import com.monta.slack.notifier.util.readStringFromFile import kotlinx.coroutines.runBlocking @@ -75,14 +77,14 @@ class PublishSlackCommand : CliktCommand() { override fun run() { runBlocking { - val githubPushContext = getGithubPushContext() + val githubEvent = getGithubEvent() PublishSlackService( serviceName = serviceName.valueOrNull(), serviceEmoji = serviceEmoji.valueOrNull(), slackToken = slackToken, slackChannelId = slackChannelId ).publish( - githubPushContext = githubPushContext, + githubEvent = githubEvent, jobType = JobType.fromString(jobType), jobStatus = JobStatus.fromString(jobStatus), slackMessageId = slackMessageId.valueOrNull() @@ -90,21 +92,24 @@ class PublishSlackCommand : CliktCommand() { } } - private fun getGithubPushContext(): GithubPushContext { + private fun getGithubEvent(): GithubEvent { + val baseGithubContext: BaseGithubContext + val eventJson = readStringFromFile(githubEventPath) - var event = JsonUtil.instance.decodeFromString(eventJson) + val event = JsonUtil.instance.decodeFromString(eventJson) - // In builds from trunk based workflows, the json event is different - // We use this hack to populate the original event with new info - if (event.headCommit == null) { - event = populateEventFromTrunkBasedEvent(eventJson, event) - } - return GithubPushContext( + // The github events can take many shapes, therefore we + // sort them and transfer them into a simpler object + baseGithubContext = populateEventFromJson(eventJson) + + return GithubEvent( repository = githubRepository, + refName = githubRefName, runId = githubRunId, - workflow = githubWorkflow, - event = event, - refName = githubRefName + displayName = baseGithubContext.displayName, + commitSHA = baseGithubContext.sha, + commitMessage = baseGithubContext.message, + workflow = githubWorkflow ) } diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/model/GithubEvent.kt b/src/commonMain/kotlin/com/monta/slack/notifier/model/GithubEvent.kt new file mode 100644 index 0000000..b063c2d --- /dev/null +++ b/src/commonMain/kotlin/com/monta/slack/notifier/model/GithubEvent.kt @@ -0,0 +1,24 @@ +package com.monta.slack.notifier.model + +class GithubEvent( + val repository: String, + val refName: String, + var runId: String, + val displayName: String?, + val commitSHA: String?, + val commitMessage: String?, + val workflow: String?, +) { + fun getRunUrl() : String { + return "https://github.com/$repository/actions/runs/$runId" + } + fun getCommitUrl() : String { + return "https://github.com/$repository/commit/$commitSHA" + } + fun getCommitMessage() : String? { + return commitMessage + ?.replace("\n", " ") + ?.replace("\r", " ") + ?.take(120) + } +} diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/model/GithubPushContext.kt b/src/commonMain/kotlin/com/monta/slack/notifier/model/GithubPushContext.kt deleted file mode 100644 index 29fd86e..0000000 --- a/src/commonMain/kotlin/com/monta/slack/notifier/model/GithubPushContext.kt +++ /dev/null @@ -1,149 +0,0 @@ -package com.monta.slack.notifier.model - -import com.monta.slack.notifier.util.buildTitle -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -data class GithubPushContext( - @SerialName("ref") - val ref: String? = null, // refs/heads/develop - @SerialName("sha") - val sha: String? = null, // c545a1613f18937a88a13935c4d644e8f81b71d6 - @SerialName("repository") - val repository: String? = null, // monta-app/service-integrations - @SerialName("run_id") - val runId: String? = null, // 4399287439 - @SerialName("actor") - val actor: String? = null, // BrianEstrada - @SerialName("triggering_actor") - val triggeringActor: String? = null, // BrianEstrada - @SerialName("workflow") - val workflow: String? = null, // Deploy Dev - @SerialName("event_name") - val eventName: String? = null, // push - @SerialName("event") - val event: Event? = null, - @SerialName("ref_name") - val refName: String? = null, // develop - @SerialName("ref_type") - val refType: String? = null, // branch -) { - - @Serializable - data class Event( - @SerialName("head_commit") - var headCommit: Commit? = null, - @SerialName("pusher") - val pusher: Committer? = null, - @SerialName("ref") - val ref: String? = null, // refs/heads/develop - ) - - @Serializable - data class Commit( - @SerialName("author") - val author: Committer? = null, - @SerialName("committer") - val committer: Committer? = null, - @SerialName("distinct") - val distinct: Boolean? = null, // true - @SerialName("id") - val id: String? = null, // c545a1613f18937a88a13935c4d644e8f81b71d6 - @SerialName("message") - val message: String? = null, // ignore: test - @SerialName("timestamp") - val timestamp: String? = null, // 2023-03-12T21:24:19+01:00 - @SerialName("tree_id") - val treeId: String? = null, // f3667a7332372de2ccb6a1cc5c310e780915a28e - @SerialName("url") - val url: String? = null, // https://github.com/monta-app/service-integrations/commit/c545a1613f18937a88a13935c4d644e8f81b71d6 - ) - - @Serializable - data class Committer( - @SerialName("email") - val email: String? = null, // lovesguitar@gmail.com - @SerialName("name") - val name: String? = null, // Brian Estrada - @SerialName("username") - val username: String? = null, // BrianEstrada - ) { - val displayName: String? = when { - email == null && name == null -> null - email == null && name != null -> name - email != null && name == null -> email - else -> "$name<$email>" - } - } - - private fun getSanitizedMessage(): String? { - return event?.headCommit?.message - ?.replace("\n", " ") - ?.replace("\r", " ") - ?.take(120) - } - - private fun getRunUrl(): String { - return "https://github.com/$repository/actions/runs/$runId" - } - - fun toMessage( - serviceName: String?, - serviceEmoji: String?, - slackChannelId: String, - messageId: String?, - attachments: List?, - ): SlackMessage { - val commit = event?.headCommit - - val title = buildTitle(repository, workflow, serviceName, serviceEmoji) - - return SlackMessage( - channel = slackChannelId, - ts = messageId, - text = title, - blocks = listOf( - SlackBlock( - type = "header", - text = SlackBlock.Text( - type = "plain_text", - text = title - ) - ), - SlackBlock( - type = "divider" - ), - SlackBlock( - type = "section", - fields = listOf( - SlackBlock.Text( - type = "mrkdwn", - text = " \n*Branch:*\n$refName" - ), - SlackBlock.Text( - type = "mrkdwn", - text = " \n*Run:*\n<${getRunUrl()}|$runId>" - ), - SlackBlock.Text( - type = "mrkdwn", - text = " \n*Comitter:*\n${commit?.committer?.displayName}" - ), - SlackBlock.Text( - type = "mrkdwn", - text = " \n*Message:*\n<${commit?.url}|${getSanitizedMessage()}>" - ), - SlackBlock.Text( - type = "mrkdwn", - text = " \n*SHA:*\n<${commit?.url}|${commit?.id}>" - ) - ) - ), - SlackBlock( - type = "divider" - ) - ), - attachments = attachments - ) - } -} diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/model/GithubTrunkBasedPushContext.kt b/src/commonMain/kotlin/com/monta/slack/notifier/model/GithubTrunkBasedPushContext.kt deleted file mode 100644 index aa6c602..0000000 --- a/src/commonMain/kotlin/com/monta/slack/notifier/model/GithubTrunkBasedPushContext.kt +++ /dev/null @@ -1,41 +0,0 @@ -package com.monta.slack.notifier.model - -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -data class GithubTrunkBasedPushContext( - @SerialName("run_id") - val runId: String? = null, // 4. Fourth var, Name of run (should be ) -) { - // In this class we grab variables from a trunk based event flow - // Where each thing we need to populate the slack message are listed - @Serializable - data class PullRequestHead( - @SerialName("ref") val ref: String, - ) - - @Serializable - data class PullRequest( - @SerialName("head") val head: PullRequestHead, - @SerialName("title") val title: String, - @SerialName("user") val user: PullRequestUser, - ) - - @Serializable - data class PullRequestUser( - @SerialName("login") val login: String, - ) - - @Serializable - data class Repository( - @SerialName("full_name") val fullName: String, - ) - - @Serializable - data class Event( - @SerialName("after") val sha: String, - @SerialName("pull_request") val pullRequest: PullRequest, - @SerialName("repository") val repository: Repository, - ) -} diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/model/serializers/BaseGithubContext.kt b/src/commonMain/kotlin/com/monta/slack/notifier/model/serializers/BaseGithubContext.kt new file mode 100644 index 0000000..539bc93 --- /dev/null +++ b/src/commonMain/kotlin/com/monta/slack/notifier/model/serializers/BaseGithubContext.kt @@ -0,0 +1,9 @@ +package com.monta.slack.notifier.model.serializers + +import kotlinx.serialization.Serializable + +class BaseGithubContext( + val displayName: String?, + val sha: String?, + val message: String?, +) diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/model/serializers/GithubCreatedContext.kt b/src/commonMain/kotlin/com/monta/slack/notifier/model/serializers/GithubCreatedContext.kt new file mode 100644 index 0000000..3be60f5 --- /dev/null +++ b/src/commonMain/kotlin/com/monta/slack/notifier/model/serializers/GithubCreatedContext.kt @@ -0,0 +1,21 @@ +package com.monta.slack.notifier.model.serializers + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +class GithubCreatedContext( + @SerialName("after") val sha: String, + @SerialName("pull_request") val pullRequest: PullRequest, +) { + @Serializable + data class PullRequest( + @SerialName("title") val title: String, + @SerialName("user") val user: PullRequestUser, + ) + + @Serializable + data class PullRequestUser( + @SerialName("login") val login: String, + ) +} diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/model/serializers/GithubOpenedContext.kt b/src/commonMain/kotlin/com/monta/slack/notifier/model/serializers/GithubOpenedContext.kt new file mode 100644 index 0000000..ca193dd --- /dev/null +++ b/src/commonMain/kotlin/com/monta/slack/notifier/model/serializers/GithubOpenedContext.kt @@ -0,0 +1,24 @@ +package com.monta.slack.notifier.model.serializers + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +class GithubOpenedContext( + @SerialName("pull_request") val pullRequest: PullRequest, +) { + @Serializable + data class PullRequest( + @SerialName("title") val title: String, + @SerialName("user") val user: PullRequestUser, + @SerialName("head") val head: PullRequestHead, + ) + @Serializable + data class PullRequestHead( + @SerialName("sha") val sha: String, + ) + @Serializable + data class PullRequestUser( + @SerialName("login") val login: String, + ) +} diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/model/serializers/GithubPushContext.kt b/src/commonMain/kotlin/com/monta/slack/notifier/model/serializers/GithubPushContext.kt new file mode 100644 index 0000000..ac6a329 --- /dev/null +++ b/src/commonMain/kotlin/com/monta/slack/notifier/model/serializers/GithubPushContext.kt @@ -0,0 +1,78 @@ +package com.monta.slack.notifier.model.serializers + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class GithubPushContext( + @SerialName("ref") + val ref: String? = null, // refs/heads/develop + @SerialName("sha") + val sha: String? = null, // c545a1613f18937a88a13935c4d644e8f81b71d6 + @SerialName("repository") + val repository: String? = null, // monta-app/service-integrations + @SerialName("run_id") + val runId: String? = null, // 4399287439 + @SerialName("actor") + val actor: String? = null, // BrianEstrada + @SerialName("triggering_actor") + val triggeringActor: String? = null, // BrianEstrada + @SerialName("workflow") + val workflow: String? = null, // Deploy Dev + @SerialName("event_name") + val eventName: String? = null, // push + @SerialName("event") + val event: Event? = null, + @SerialName("ref_name") + val refName: String? = null, // develop + @SerialName("ref_type") + val refType: String? = null, // branch +) { + + @Serializable + data class Event( + @SerialName("head_commit") + var headCommit: Commit, + @SerialName("pusher") + val pusher: Committer, + @SerialName("ref") + val ref: String? = null, // refs/heads/develop + ) + + @Serializable + data class Commit( + @SerialName("author") + val author: Committer? = null, + @SerialName("committer") + val committer: Committer? = null, + @SerialName("distinct") + val distinct: Boolean? = null, // true + @SerialName("id") + val id: String, // c545a1613f18937a88a13935c4d644e8f81b71d6 + @SerialName("message") + val message: String, // ignore: test + @SerialName("timestamp") + val timestamp: String? = null, // 2023-03-12T21:24:19+01:00 + @SerialName("tree_id") + val treeId: String? = null, // f3667a7332372de2ccb6a1cc5c310e780915a28e + @SerialName("url") + val url: String? = null, // https://github.com/monta-app/service-integrations/commit/c545a1613f18937a88a13935c4d644e8f81b71d6 + ) + + @Serializable + data class Committer( + @SerialName("email") + val email: String? = null, // lovesguitar@gmail.com + @SerialName("name") + val name: String? = null, // Brian Estrada + @SerialName("username") + val username: String? = null, // BrianEstrada + ) { + val displayName: String = when { + email == null && name == null -> "N/A" + email == null && name != null -> name + email != null && name == null -> email + else -> "$name<$email>" + } + } +} diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/service/PublishSlackService.kt b/src/commonMain/kotlin/com/monta/slack/notifier/service/PublishSlackService.kt index 4d0838d..0696d36 100644 --- a/src/commonMain/kotlin/com/monta/slack/notifier/service/PublishSlackService.kt +++ b/src/commonMain/kotlin/com/monta/slack/notifier/service/PublishSlackService.kt @@ -1,7 +1,7 @@ package com.monta.slack.notifier.service import com.monta.slack.notifier.SlackClient -import com.monta.slack.notifier.model.GithubPushContext +import com.monta.slack.notifier.model.GithubEvent import com.monta.slack.notifier.model.JobStatus import com.monta.slack.notifier.model.JobType import com.monta.slack.notifier.util.writeToOutput @@ -21,21 +21,21 @@ class PublishSlackService( ) suspend fun publish( - githubPushContext: GithubPushContext, + githubEvent: GithubEvent, jobType: JobType, jobStatus: JobStatus, slackMessageId: String?, ): String { val messageId = if (slackMessageId.isNullOrBlank()) { slackClient.create( - githubPushContext = githubPushContext, + githubEvent = githubEvent, jobType = jobType, jobStatus = jobStatus ) } else { slackClient.update( messageId = slackMessageId, - githubPushContext = githubPushContext, + githubEvent = githubEvent, jobType = jobType, jobStatus = jobStatus ) diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/util/FileUtils.kt b/src/commonMain/kotlin/com/monta/slack/notifier/util/FileUtils.kt index 5821344..34b4c82 100644 --- a/src/commonMain/kotlin/com/monta/slack/notifier/util/FileUtils.kt +++ b/src/commonMain/kotlin/com/monta/slack/notifier/util/FileUtils.kt @@ -1,13 +1,19 @@ package com.monta.slack.notifier.util +import com.monta.slack.notifier.model.serializers.BaseGithubContext +import com.monta.slack.notifier.model.serializers.GithubCreatedContext +import com.monta.slack.notifier.model.serializers.GithubOpenedContext +import com.monta.slack.notifier.model.serializers.GithubPushContext import kotlinx.cinterop.ByteVar import kotlinx.cinterop.ExperimentalForeignApi import kotlinx.cinterop.allocArray import kotlinx.cinterop.memScoped import kotlinx.cinterop.toKString +import kotlinx.serialization.ExperimentalSerializationApi import platform.posix.fclose import platform.posix.fgets import platform.posix.fopen +import kotlinx.serialization.MissingFieldException @OptIn(ExperimentalForeignApi::class) fun readStringFromFile( @@ -30,3 +36,62 @@ fun readStringFromFile( } return returnBuffer.toString() } + +/** + * Populates the existing event type with information needed to generate + * an entire Slack notification. + */ +fun populateEventFromJson(eventJson: String): BaseGithubContext { + return populateOnJsonPush(eventJson) ?: populateOnJsonOpened(eventJson) ?: populateOnJsonCreated(eventJson) ?: handleFailure() +} + +@OptIn(ExperimentalSerializationApi::class) +private fun populateOnJsonPush(eventJson: String): BaseGithubContext? { + return try { + val event = JsonUtil.instance.decodeFromString(eventJson) + + return BaseGithubContext( + displayName = event.pusher.displayName, + sha = event.headCommit.id, + message = event.headCommit.message + ) + } catch (e: MissingFieldException) { + null + } +} +@OptIn(ExperimentalSerializationApi::class) +private fun populateOnJsonOpened(eventJson: String): BaseGithubContext? { + return try { + val event = JsonUtil.instance.decodeFromString(eventJson) + + return BaseGithubContext( + displayName = event.pullRequest.user.login, + sha = event.pullRequest.head.sha, + message = event.pullRequest.title + ) + } catch (e: MissingFieldException) { + null + } +} +@OptIn(ExperimentalSerializationApi::class) +private fun populateOnJsonCreated(eventJson: String): BaseGithubContext? { + return try { + val event = JsonUtil.instance.decodeFromString(eventJson) + + return BaseGithubContext( + displayName = event.pullRequest.user.login, + sha = event.sha, + message = event.pullRequest.title + ) + } catch (e: MissingFieldException) { + null + } +} + +private fun handleFailure(): BaseGithubContext { + return BaseGithubContext( + displayName = null, + sha = null, + message = null + ) +} diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/util/TrunkUtils.kt b/src/commonMain/kotlin/com/monta/slack/notifier/util/TrunkUtils.kt deleted file mode 100644 index 9cb1d3d..0000000 --- a/src/commonMain/kotlin/com/monta/slack/notifier/util/TrunkUtils.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.monta.slack.notifier.util - -import com.monta.slack.notifier.model.GithubPushContext -import com.monta.slack.notifier.model.GithubTrunkBasedPushContext - -/** - * Populates the existing event type with information needed to generate - * an entire Slack notification. This is super hacky but an easy solution - * without deintegrating GithubPushContext from the rest of the code. - */ -fun populateEventFromTrunkBasedEvent(eventJson: String, event: GithubPushContext.Event): GithubPushContext.Event { - val trunkBasedEvent = JsonUtil.instance.decodeFromString(eventJson) - event.headCommit = GithubPushContext.Commit( - committer = GithubPushContext.Committer(name = trunkBasedEvent.pullRequest.user.login), - id = trunkBasedEvent.sha, - url = "https://github.com/${trunkBasedEvent.repository.fullName}/compare/${trunkBasedEvent.pullRequest.head.ref}", - message = trunkBasedEvent.pullRequest.title - ) - return event -} From a67f3e21e9443f2b67eec6e3f270fd2ce236bae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Z=C3=B8rn?= Date: Mon, 29 Apr 2024 18:17:07 +0200 Subject: [PATCH 2/5] Change exception codes and kt lint --- .../kotlin/com/monta/slack/notifier/SlackClient.kt | 1 - .../slack/notifier/command/PublishSlackCommand.kt | 5 +---- .../com/monta/slack/notifier/model/GithubEvent.kt | 8 ++++---- .../notifier/model/serializers/BaseGithubContext.kt | 2 -- .../model/serializers/GithubOpenedContext.kt | 2 ++ .../com/monta/slack/notifier/util/FileUtils.kt | 13 ++++++------- 6 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/SlackClient.kt b/src/commonMain/kotlin/com/monta/slack/notifier/SlackClient.kt index 8b741ce..5bbc05f 100644 --- a/src/commonMain/kotlin/com/monta/slack/notifier/SlackClient.kt +++ b/src/commonMain/kotlin/com/monta/slack/notifier/SlackClient.kt @@ -69,7 +69,6 @@ class SlackClient( messageId: String?, attachments: List?, ): SlackMessage { - val title = buildTitle(githubEvent.repository, githubEvent.workflow, serviceName, serviceEmoji) return SlackMessage( diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/command/PublishSlackCommand.kt b/src/commonMain/kotlin/com/monta/slack/notifier/command/PublishSlackCommand.kt index 8bf09e4..b38601f 100644 --- a/src/commonMain/kotlin/com/monta/slack/notifier/command/PublishSlackCommand.kt +++ b/src/commonMain/kotlin/com/monta/slack/notifier/command/PublishSlackCommand.kt @@ -4,12 +4,10 @@ import com.github.ajalt.clikt.core.CliktCommand import com.github.ajalt.clikt.parameters.options.option import com.github.ajalt.clikt.parameters.options.required import com.monta.slack.notifier.model.GithubEvent -import com.monta.slack.notifier.model.serializers.GithubPushContext import com.monta.slack.notifier.model.JobStatus import com.monta.slack.notifier.model.JobType import com.monta.slack.notifier.model.serializers.BaseGithubContext import com.monta.slack.notifier.service.PublishSlackService -import com.monta.slack.notifier.util.JsonUtil import com.monta.slack.notifier.util.populateEventFromJson import com.monta.slack.notifier.util.readStringFromFile import kotlinx.coroutines.runBlocking @@ -96,9 +94,8 @@ class PublishSlackCommand : CliktCommand() { val baseGithubContext: BaseGithubContext val eventJson = readStringFromFile(githubEventPath) - val event = JsonUtil.instance.decodeFromString(eventJson) - // The github events can take many shapes, therefore we + // The Github events can take many shapes, therefore we // sort them and transfer them into a simpler object baseGithubContext = populateEventFromJson(eventJson) diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/model/GithubEvent.kt b/src/commonMain/kotlin/com/monta/slack/notifier/model/GithubEvent.kt index b063c2d..404a506 100644 --- a/src/commonMain/kotlin/com/monta/slack/notifier/model/GithubEvent.kt +++ b/src/commonMain/kotlin/com/monta/slack/notifier/model/GithubEvent.kt @@ -8,14 +8,14 @@ class GithubEvent( val commitSHA: String?, val commitMessage: String?, val workflow: String?, -) { - fun getRunUrl() : String { +) { + fun getRunUrl(): String { return "https://github.com/$repository/actions/runs/$runId" } - fun getCommitUrl() : String { + fun getCommitUrl(): String { return "https://github.com/$repository/commit/$commitSHA" } - fun getCommitMessage() : String? { + fun getCommitMessage(): String? { return commitMessage ?.replace("\n", " ") ?.replace("\r", " ") diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/model/serializers/BaseGithubContext.kt b/src/commonMain/kotlin/com/monta/slack/notifier/model/serializers/BaseGithubContext.kt index 539bc93..bf5d137 100644 --- a/src/commonMain/kotlin/com/monta/slack/notifier/model/serializers/BaseGithubContext.kt +++ b/src/commonMain/kotlin/com/monta/slack/notifier/model/serializers/BaseGithubContext.kt @@ -1,7 +1,5 @@ package com.monta.slack.notifier.model.serializers -import kotlinx.serialization.Serializable - class BaseGithubContext( val displayName: String?, val sha: String?, diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/model/serializers/GithubOpenedContext.kt b/src/commonMain/kotlin/com/monta/slack/notifier/model/serializers/GithubOpenedContext.kt index ca193dd..0277e4b 100644 --- a/src/commonMain/kotlin/com/monta/slack/notifier/model/serializers/GithubOpenedContext.kt +++ b/src/commonMain/kotlin/com/monta/slack/notifier/model/serializers/GithubOpenedContext.kt @@ -13,10 +13,12 @@ class GithubOpenedContext( @SerialName("user") val user: PullRequestUser, @SerialName("head") val head: PullRequestHead, ) + @Serializable data class PullRequestHead( @SerialName("sha") val sha: String, ) + @Serializable data class PullRequestUser( @SerialName("login") val login: String, diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/util/FileUtils.kt b/src/commonMain/kotlin/com/monta/slack/notifier/util/FileUtils.kt index 34b4c82..235cc64 100644 --- a/src/commonMain/kotlin/com/monta/slack/notifier/util/FileUtils.kt +++ b/src/commonMain/kotlin/com/monta/slack/notifier/util/FileUtils.kt @@ -10,10 +10,10 @@ import kotlinx.cinterop.allocArray import kotlinx.cinterop.memScoped import kotlinx.cinterop.toKString import kotlinx.serialization.ExperimentalSerializationApi +import kotlinx.serialization.SerializationException import platform.posix.fclose import platform.posix.fgets import platform.posix.fopen -import kotlinx.serialization.MissingFieldException @OptIn(ExperimentalForeignApi::class) fun readStringFromFile( @@ -49,41 +49,40 @@ fun populateEventFromJson(eventJson: String): BaseGithubContext { private fun populateOnJsonPush(eventJson: String): BaseGithubContext? { return try { val event = JsonUtil.instance.decodeFromString(eventJson) - return BaseGithubContext( displayName = event.pusher.displayName, sha = event.headCommit.id, message = event.headCommit.message ) - } catch (e: MissingFieldException) { + } catch (e: SerializationException) { null } } + @OptIn(ExperimentalSerializationApi::class) private fun populateOnJsonOpened(eventJson: String): BaseGithubContext? { return try { val event = JsonUtil.instance.decodeFromString(eventJson) - return BaseGithubContext( displayName = event.pullRequest.user.login, sha = event.pullRequest.head.sha, message = event.pullRequest.title ) - } catch (e: MissingFieldException) { + } catch (e: SerializationException) { null } } + @OptIn(ExperimentalSerializationApi::class) private fun populateOnJsonCreated(eventJson: String): BaseGithubContext? { return try { val event = JsonUtil.instance.decodeFromString(eventJson) - return BaseGithubContext( displayName = event.pullRequest.user.login, sha = event.sha, message = event.pullRequest.title ) - } catch (e: MissingFieldException) { + } catch (e: SerializationException) { null } } From 54b6bcd7f739bea321222af2b560ac3235f99d28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Z=C3=B8rn?= Date: Tue, 30 Apr 2024 09:29:23 +0200 Subject: [PATCH 3/5] Delete event.yaml --- event.yaml | 505 ----------------------------------------------------- 1 file changed, 505 deletions(-) delete mode 100644 event.yaml diff --git a/event.yaml b/event.yaml deleted file mode 100644 index 7a5a750..0000000 --- a/event.yaml +++ /dev/null @@ -1,505 +0,0 @@ -{ - "action": "synchronize", - "after": "06113c1af18885efc43e8ce60f94cd79f651a71f", - "before": "09f10a7de2ff88f2e81497d3429f062b482ea4e9", - "number": 49, - "organization": { - "avatar_url": "https://avatars.githubusercontent.com/u/70286931?v=4", - "description": "EV Better", - "events_url": "https://api.github.com/orgs/monta-app/events", - "hooks_url": "https://api.github.com/orgs/monta-app/hooks", - "id": 70286931, - "issues_url": "https://api.github.com/orgs/monta-app/issues", - "login": "monta-app", - "members_url": "https://api.github.com/orgs/monta-app/members{/member}", - "node_id": "MDEyOk9yZ2FuaXphdGlvbjcwMjg2OTMx", - "public_members_url": "https://api.github.com/orgs/monta-app/public_members{/member}", - "repos_url": "https://api.github.com/orgs/monta-app/repos", - "url": "https://api.github.com/orgs/monta-app" - }, - "pull_request": { - "_links": { - "comments": { - "href": "https://api.github.com/repos/monta-app/data-smart-charge/issues/49/comments" - }, - "commits": { - "href": "https://api.github.com/repos/monta-app/data-smart-charge/pulls/49/commits" - }, - "html": { - "href": "https://github.com/monta-app/data-smart-charge/pull/49" - }, - "issue": { - "href": "https://api.github.com/repos/monta-app/data-smart-charge/issues/49" - }, - "review_comment": { - "href": "https://api.github.com/repos/monta-app/data-smart-charge/pulls/comments{/number}" - }, - "review_comments": { - "href": "https://api.github.com/repos/monta-app/data-smart-charge/pulls/49/comments" - }, - "self": { - "href": "https://api.github.com/repos/monta-app/data-smart-charge/pulls/49" - }, - "statuses": { - "href": "https://api.github.com/repos/monta-app/data-smart-charge/statuses/06113c1af18885efc43e8ce60f94cd79f651a71f" - } - }, - "active_lock_reason": null, - "additions": 6, - "assignee": null, - "assignees": [], - "author_association": "CONTRIBUTOR", - "auto_merge": null, - "base": { - "label": "monta-app:main", - "ref": "main", - "repo": { - "allow_auto_merge": false, - "allow_forking": false, - "allow_merge_commit": true, - "allow_rebase_merge": true, - "allow_squash_merge": true, - "allow_update_branch": false, - "archive_url": "https://api.github.com/repos/monta-app/data-smart-charge/{archive_format}{/ref}", - "archived": false, - "assignees_url": "https://api.github.com/repos/monta-app/data-smart-charge/assignees{/user}", - "blobs_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/blobs{/sha}", - "branches_url": "https://api.github.com/repos/monta-app/data-smart-charge/branches{/branch}", - "clone_url": "https://github.com/monta-app/data-smart-charge.git", - "collaborators_url": "https://api.github.com/repos/monta-app/data-smart-charge/collaborators{/collaborator}", - "comments_url": "https://api.github.com/repos/monta-app/data-smart-charge/comments{/number}", - "commits_url": "https://api.github.com/repos/monta-app/data-smart-charge/commits{/sha}", - "compare_url": "https://api.github.com/repos/monta-app/data-smart-charge/compare/{base}...{head}", - "contents_url": "https://api.github.com/repos/monta-app/data-smart-charge/contents/{+path}", - "contributors_url": "https://api.github.com/repos/monta-app/data-smart-charge/contributors", - "created_at": "2024-02-09T13:53:23Z", - "default_branch": "main", - "delete_branch_on_merge": false, - "deployments_url": "https://api.github.com/repos/monta-app/data-smart-charge/deployments", - "description": "Smart charge service", - "disabled": false, - "downloads_url": "https://api.github.com/repos/monta-app/data-smart-charge/downloads", - "events_url": "https://api.github.com/repos/monta-app/data-smart-charge/events", - "fork": false, - "forks": 0, - "forks_count": 0, - "forks_url": "https://api.github.com/repos/monta-app/data-smart-charge/forks", - "full_name": "monta-app/data-smart-charge", - "git_commits_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/commits{/sha}", - "git_refs_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/refs{/sha}", - "git_tags_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/tags{/sha}", - "git_url": "git://github.com/monta-app/data-smart-charge.git", - "has_discussions": false, - "has_downloads": true, - "has_issues": true, - "has_pages": false, - "has_projects": true, - "has_wiki": true, - "homepage": "", - "hooks_url": "https://api.github.com/repos/monta-app/data-smart-charge/hooks", - "html_url": "https://github.com/monta-app/data-smart-charge", - "id": 755136543, - "is_template": false, - "issue_comment_url": "https://api.github.com/repos/monta-app/data-smart-charge/issues/comments{/number}", - "issue_events_url": "https://api.github.com/repos/monta-app/data-smart-charge/issues/events{/number}", - "issues_url": "https://api.github.com/repos/monta-app/data-smart-charge/issues{/number}", - "keys_url": "https://api.github.com/repos/monta-app/data-smart-charge/keys{/key_id}", - "labels_url": "https://api.github.com/repos/monta-app/data-smart-charge/labels{/name}", - "language": "Python", - "languages_url": "https://api.github.com/repos/monta-app/data-smart-charge/languages", - "license": null, - "merge_commit_message": "PR_TITLE", - "merge_commit_title": "MERGE_MESSAGE", - "merges_url": "https://api.github.com/repos/monta-app/data-smart-charge/merges", - "milestones_url": "https://api.github.com/repos/monta-app/data-smart-charge/milestones{/number}", - "mirror_url": null, - "name": "data-smart-charge", - "node_id": "R_kgDOLQJ4Hw", - "notifications_url": "https://api.github.com/repos/monta-app/data-smart-charge/notifications{?since,all,participating}", - "open_issues": 7, - "open_issues_count": 7, - "owner": { - "avatar_url": "https://avatars.githubusercontent.com/u/70286931?v=4", - "events_url": "https://api.github.com/users/monta-app/events{/privacy}", - "followers_url": "https://api.github.com/users/monta-app/followers", - "following_url": "https://api.github.com/users/monta-app/following{/other_user}", - "gists_url": "https://api.github.com/users/monta-app/gists{/gist_id}", - "gravatar_id": "", - "html_url": "https://github.com/monta-app", - "id": 70286931, - "login": "monta-app", - "node_id": "MDEyOk9yZ2FuaXphdGlvbjcwMjg2OTMx", - "organizations_url": "https://api.github.com/users/monta-app/orgs", - "received_events_url": "https://api.github.com/users/monta-app/received_events", - "repos_url": "https://api.github.com/users/monta-app/repos", - "site_admin": false, - "starred_url": "https://api.github.com/users/monta-app/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/monta-app/subscriptions", - "type": "Organization", - "url": "https://api.github.com/users/monta-app" - }, - "private": true, - "pulls_url": "https://api.github.com/repos/monta-app/data-smart-charge/pulls{/number}", - "pushed_at": "2024-04-26T10:35:29Z", - "releases_url": "https://api.github.com/repos/monta-app/data-smart-charge/releases{/id}", - "size": 733, - "squash_merge_commit_message": "COMMIT_MESSAGES", - "squash_merge_commit_title": "COMMIT_OR_PR_TITLE", - "ssh_url": "git@github.com:monta-app/data-smart-charge.git", - "stargazers_count": 1, - "stargazers_url": "https://api.github.com/repos/monta-app/data-smart-charge/stargazers", - "statuses_url": "https://api.github.com/repos/monta-app/data-smart-charge/statuses/{sha}", - "subscribers_url": "https://api.github.com/repos/monta-app/data-smart-charge/subscribers", - "subscription_url": "https://api.github.com/repos/monta-app/data-smart-charge/subscription", - "svn_url": "https://github.com/monta-app/data-smart-charge", - "tags_url": "https://api.github.com/repos/monta-app/data-smart-charge/tags", - "teams_url": "https://api.github.com/repos/monta-app/data-smart-charge/teams", - "topics": [], - "trees_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/trees{/sha}", - "updated_at": "2024-04-26T10:20:57Z", - "url": "https://api.github.com/repos/monta-app/data-smart-charge", - "use_squash_pr_title_as_default": false, - "visibility": "private", - "watchers": 1, - "watchers_count": 1, - "web_commit_signoff_required": false - }, - "sha": "673ac883ed63a26806babac4b6deb24307f37cdc", - "user": { - "avatar_url": "https://avatars.githubusercontent.com/u/70286931?v=4", - "events_url": "https://api.github.com/users/monta-app/events{/privacy}", - "followers_url": "https://api.github.com/users/monta-app/followers", - "following_url": "https://api.github.com/users/monta-app/following{/other_user}", - "gists_url": "https://api.github.com/users/monta-app/gists{/gist_id}", - "gravatar_id": "", - "html_url": "https://github.com/monta-app", - "id": 70286931, - "login": "monta-app", - "node_id": "MDEyOk9yZ2FuaXphdGlvbjcwMjg2OTMx", - "organizations_url": "https://api.github.com/users/monta-app/orgs", - "received_events_url": "https://api.github.com/users/monta-app/received_events", - "repos_url": "https://api.github.com/users/monta-app/repos", - "site_admin": false, - "starred_url": "https://api.github.com/users/monta-app/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/monta-app/subscriptions", - "type": "Organization", - "url": "https://api.github.com/users/monta-app" - } - }, - "body": null, - "changed_files": 2, - "closed_at": null, - "comments": 1, - "comments_url": "https://api.github.com/repos/monta-app/data-smart-charge/issues/49/comments", - "commits": 2, - "commits_url": "https://api.github.com/repos/monta-app/data-smart-charge/pulls/49/commits", - "created_at": "2024-04-26T10:34:20Z", - "deletions": 6, - "diff_url": "https://github.com/monta-app/data-smart-charge/pull/49.diff", - "draft": false, - "head": { - "label": "monta-app:fix/revert-slack-notif-cli-version", - "ref": "fix/revert-slack-notif-cli-version", - "repo": { - "allow_auto_merge": false, - "allow_forking": false, - "allow_merge_commit": true, - "allow_rebase_merge": true, - "allow_squash_merge": true, - "allow_update_branch": false, - "archive_url": "https://api.github.com/repos/monta-app/data-smart-charge/{archive_format}{/ref}", - "archived": false, - "assignees_url": "https://api.github.com/repos/monta-app/data-smart-charge/assignees{/user}", - "blobs_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/blobs{/sha}", - "branches_url": "https://api.github.com/repos/monta-app/data-smart-charge/branches{/branch}", - "clone_url": "https://github.com/monta-app/data-smart-charge.git", - "collaborators_url": "https://api.github.com/repos/monta-app/data-smart-charge/collaborators{/collaborator}", - "comments_url": "https://api.github.com/repos/monta-app/data-smart-charge/comments{/number}", - "commits_url": "https://api.github.com/repos/monta-app/data-smart-charge/commits{/sha}", - "compare_url": "https://api.github.com/repos/monta-app/data-smart-charge/compare/{base}...{head}", - "contents_url": "https://api.github.com/repos/monta-app/data-smart-charge/contents/{+path}", - "contributors_url": "https://api.github.com/repos/monta-app/data-smart-charge/contributors", - "created_at": "2024-02-09T13:53:23Z", - "default_branch": "main", - "delete_branch_on_merge": false, - "deployments_url": "https://api.github.com/repos/monta-app/data-smart-charge/deployments", - "description": "Smart charge service", - "disabled": false, - "downloads_url": "https://api.github.com/repos/monta-app/data-smart-charge/downloads", - "events_url": "https://api.github.com/repos/monta-app/data-smart-charge/events", - "fork": false, - "forks": 0, - "forks_count": 0, - "forks_url": "https://api.github.com/repos/monta-app/data-smart-charge/forks", - "full_name": "monta-app/data-smart-charge", - "git_commits_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/commits{/sha}", - "git_refs_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/refs{/sha}", - "git_tags_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/tags{/sha}", - "git_url": "git://github.com/monta-app/data-smart-charge.git", - "has_discussions": false, - "has_downloads": true, - "has_issues": true, - "has_pages": false, - "has_projects": true, - "has_wiki": true, - "homepage": "", - "hooks_url": "https://api.github.com/repos/monta-app/data-smart-charge/hooks", - "html_url": "https://github.com/monta-app/data-smart-charge", - "id": 755136543, - "is_template": false, - "issue_comment_url": "https://api.github.com/repos/monta-app/data-smart-charge/issues/comments{/number}", - "issue_events_url": "https://api.github.com/repos/monta-app/data-smart-charge/issues/events{/number}", - "issues_url": "https://api.github.com/repos/monta-app/data-smart-charge/issues{/number}", - "keys_url": "https://api.github.com/repos/monta-app/data-smart-charge/keys{/key_id}", - "labels_url": "https://api.github.com/repos/monta-app/data-smart-charge/labels{/name}", - "language": "Python", - "languages_url": "https://api.github.com/repos/monta-app/data-smart-charge/languages", - "license": null, - "merge_commit_message": "PR_TITLE", - "merge_commit_title": "MERGE_MESSAGE", - "merges_url": "https://api.github.com/repos/monta-app/data-smart-charge/merges", - "milestones_url": "https://api.github.com/repos/monta-app/data-smart-charge/milestones{/number}", - "mirror_url": null, - "name": "data-smart-charge", - "node_id": "R_kgDOLQJ4Hw", - "notifications_url": "https://api.github.com/repos/monta-app/data-smart-charge/notifications{?since,all,participating}", - "open_issues": 7, - "open_issues_count": 7, - "owner": { - "avatar_url": "https://avatars.githubusercontent.com/u/70286931?v=4", - "events_url": "https://api.github.com/users/monta-app/events{/privacy}", - "followers_url": "https://api.github.com/users/monta-app/followers", - "following_url": "https://api.github.com/users/monta-app/following{/other_user}", - "gists_url": "https://api.github.com/users/monta-app/gists{/gist_id}", - "gravatar_id": "", - "html_url": "https://github.com/monta-app", - "id": 70286931, - "login": "monta-app", - "node_id": "MDEyOk9yZ2FuaXphdGlvbjcwMjg2OTMx", - "organizations_url": "https://api.github.com/users/monta-app/orgs", - "received_events_url": "https://api.github.com/users/monta-app/received_events", - "repos_url": "https://api.github.com/users/monta-app/repos", - "site_admin": false, - "starred_url": "https://api.github.com/users/monta-app/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/monta-app/subscriptions", - "type": "Organization", - "url": "https://api.github.com/users/monta-app" - }, - "private": true, - "pulls_url": "https://api.github.com/repos/monta-app/data-smart-charge/pulls{/number}", - "pushed_at": "2024-04-26T10:35:29Z", - "releases_url": "https://api.github.com/repos/monta-app/data-smart-charge/releases{/id}", - "size": 733, - "squash_merge_commit_message": "COMMIT_MESSAGES", - "squash_merge_commit_title": "COMMIT_OR_PR_TITLE", - "ssh_url": "git@github.com:monta-app/data-smart-charge.git", - "stargazers_count": 1, - "stargazers_url": "https://api.github.com/repos/monta-app/data-smart-charge/stargazers", - "statuses_url": "https://api.github.com/repos/monta-app/data-smart-charge/statuses/{sha}", - "subscribers_url": "https://api.github.com/repos/monta-app/data-smart-charge/subscribers", - "subscription_url": "https://api.github.com/repos/monta-app/data-smart-charge/subscription", - "svn_url": "https://github.com/monta-app/data-smart-charge", - "tags_url": "https://api.github.com/repos/monta-app/data-smart-charge/tags", - "teams_url": "https://api.github.com/repos/monta-app/data-smart-charge/teams", - "topics": [], - "trees_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/trees{/sha}", - "updated_at": "2024-04-26T10:20:57Z", - "url": "https://api.github.com/repos/monta-app/data-smart-charge", - "use_squash_pr_title_as_default": false, - "visibility": "private", - "watchers": 1, - "watchers_count": 1, - "web_commit_signoff_required": false - }, - "sha": "06113c1af18885efc43e8ce60f94cd79f651a71f", - "user": { - "avatar_url": "https://avatars.githubusercontent.com/u/70286931?v=4", - "events_url": "https://api.github.com/users/monta-app/events{/privacy}", - "followers_url": "https://api.github.com/users/monta-app/followers", - "following_url": "https://api.github.com/users/monta-app/following{/other_user}", - "gists_url": "https://api.github.com/users/monta-app/gists{/gist_id}", - "gravatar_id": "", - "html_url": "https://github.com/monta-app", - "id": 70286931, - "login": "monta-app", - "node_id": "MDEyOk9yZ2FuaXphdGlvbjcwMjg2OTMx", - "organizations_url": "https://api.github.com/users/monta-app/orgs", - "received_events_url": "https://api.github.com/users/monta-app/received_events", - "repos_url": "https://api.github.com/users/monta-app/repos", - "site_admin": false, - "starred_url": "https://api.github.com/users/monta-app/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/monta-app/subscriptions", - "type": "Organization", - "url": "https://api.github.com/users/monta-app" - } - }, - "html_url": "https://github.com/monta-app/data-smart-charge/pull/49", - "id": 1842600504, - "issue_url": "https://api.github.com/repos/monta-app/data-smart-charge/issues/49", - "labels": [], - "locked": false, - "maintainer_can_modify": false, - "merge_commit_sha": "a9490f607c5c4dfc713e0dea5067ba9d49c384a6", - "mergeable": null, - "mergeable_state": "unknown", - "merged": false, - "merged_at": null, - "merged_by": null, - "milestone": null, - "node_id": "PR_kwDOLQJ4H85t09o4", - "number": 49, - "patch_url": "https://github.com/monta-app/data-smart-charge/pull/49.patch", - "rebaseable": null, - "requested_reviewers": [], - "requested_teams": [], - "review_comment_url": "https://api.github.com/repos/monta-app/data-smart-charge/pulls/comments{/number}", - "review_comments": 0, - "review_comments_url": "https://api.github.com/repos/monta-app/data-smart-charge/pulls/49/comments", - "state": "open", - "statuses_url": "https://api.github.com/repos/monta-app/data-smart-charge/statuses/06113c1af18885efc43e8ce60f94cd79f651a71f", - "title": "fix(workflow): revert to main version of slack notif cli", - "updated_at": "2024-04-26T10:35:30Z", - "url": "https://api.github.com/repos/monta-app/data-smart-charge/pulls/49", - "user": { - "avatar_url": "https://avatars.githubusercontent.com/u/63373006?v=4", - "events_url": "https://api.github.com/users/baldm/events{/privacy}", - "followers_url": "https://api.github.com/users/baldm/followers", - "following_url": "https://api.github.com/users/baldm/following{/other_user}", - "gists_url": "https://api.github.com/users/baldm/gists{/gist_id}", - "gravatar_id": "", - "html_url": "https://github.com/baldm", - "id": 63373006, - "login": "baldm", - "node_id": "MDQ6VXNlcjYzMzczMDA2", - "organizations_url": "https://api.github.com/users/baldm/orgs", - "received_events_url": "https://api.github.com/users/baldm/received_events", - "repos_url": "https://api.github.com/users/baldm/repos", - "site_admin": false, - "starred_url": "https://api.github.com/users/baldm/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/baldm/subscriptions", - "type": "User", - "url": "https://api.github.com/users/baldm" - } - }, - "repository": { - "allow_forking": false, - "archive_url": "https://api.github.com/repos/monta-app/data-smart-charge/{archive_format}{/ref}", - "archived": false, - "assignees_url": "https://api.github.com/repos/monta-app/data-smart-charge/assignees{/user}", - "blobs_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/blobs{/sha}", - "branches_url": "https://api.github.com/repos/monta-app/data-smart-charge/branches{/branch}", - "clone_url": "https://github.com/monta-app/data-smart-charge.git", - "collaborators_url": "https://api.github.com/repos/monta-app/data-smart-charge/collaborators{/collaborator}", - "comments_url": "https://api.github.com/repos/monta-app/data-smart-charge/comments{/number}", - "commits_url": "https://api.github.com/repos/monta-app/data-smart-charge/commits{/sha}", - "compare_url": "https://api.github.com/repos/monta-app/data-smart-charge/compare/{base}...{head}", - "contents_url": "https://api.github.com/repos/monta-app/data-smart-charge/contents/{+path}", - "contributors_url": "https://api.github.com/repos/monta-app/data-smart-charge/contributors", - "created_at": "2024-02-09T13:53:23Z", - "custom_properties": {}, - "default_branch": "main", - "deployments_url": "https://api.github.com/repos/monta-app/data-smart-charge/deployments", - "description": "Smart charge service", - "disabled": false, - "downloads_url": "https://api.github.com/repos/monta-app/data-smart-charge/downloads", - "events_url": "https://api.github.com/repos/monta-app/data-smart-charge/events", - "fork": false, - "forks": 0, - "forks_count": 0, - "forks_url": "https://api.github.com/repos/monta-app/data-smart-charge/forks", - "full_name": "monta-app/data-smart-charge", - "git_commits_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/commits{/sha}", - "git_refs_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/refs{/sha}", - "git_tags_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/tags{/sha}", - "git_url": "git://github.com/monta-app/data-smart-charge.git", - "has_discussions": false, - "has_downloads": true, - "has_issues": true, - "has_pages": false, - "has_projects": true, - "has_wiki": true, - "homepage": "", - "hooks_url": "https://api.github.com/repos/monta-app/data-smart-charge/hooks", - "html_url": "https://github.com/monta-app/data-smart-charge", - "id": 755136543, - "is_template": false, - "issue_comment_url": "https://api.github.com/repos/monta-app/data-smart-charge/issues/comments{/number}", - "issue_events_url": "https://api.github.com/repos/monta-app/data-smart-charge/issues/events{/number}", - "issues_url": "https://api.github.com/repos/monta-app/data-smart-charge/issues{/number}", - "keys_url": "https://api.github.com/repos/monta-app/data-smart-charge/keys{/key_id}", - "labels_url": "https://api.github.com/repos/monta-app/data-smart-charge/labels{/name}", - "language": "Python", - "languages_url": "https://api.github.com/repos/monta-app/data-smart-charge/languages", - "license": null, - "merges_url": "https://api.github.com/repos/monta-app/data-smart-charge/merges", - "milestones_url": "https://api.github.com/repos/monta-app/data-smart-charge/milestones{/number}", - "mirror_url": null, - "name": "data-smart-charge", - "node_id": "R_kgDOLQJ4Hw", - "notifications_url": "https://api.github.com/repos/monta-app/data-smart-charge/notifications{?since,all,participating}", - "open_issues": 7, - "open_issues_count": 7, - "owner": { - "avatar_url": "https://avatars.githubusercontent.com/u/70286931?v=4", - "events_url": "https://api.github.com/users/monta-app/events{/privacy}", - "followers_url": "https://api.github.com/users/monta-app/followers", - "following_url": "https://api.github.com/users/monta-app/following{/other_user}", - "gists_url": "https://api.github.com/users/monta-app/gists{/gist_id}", - "gravatar_id": "", - "html_url": "https://github.com/monta-app", - "id": 70286931, - "login": "monta-app", - "node_id": "MDEyOk9yZ2FuaXphdGlvbjcwMjg2OTMx", - "organizations_url": "https://api.github.com/users/monta-app/orgs", - "received_events_url": "https://api.github.com/users/monta-app/received_events", - "repos_url": "https://api.github.com/users/monta-app/repos", - "site_admin": false, - "starred_url": "https://api.github.com/users/monta-app/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/monta-app/subscriptions", - "type": "Organization", - "url": "https://api.github.com/users/monta-app" - }, - "private": true, - "pulls_url": "https://api.github.com/repos/monta-app/data-smart-charge/pulls{/number}", - "pushed_at": "2024-04-26T10:35:29Z", - "releases_url": "https://api.github.com/repos/monta-app/data-smart-charge/releases{/id}", - "size": 733, - "ssh_url": "git@github.com:monta-app/data-smart-charge.git", - "stargazers_count": 1, - "stargazers_url": "https://api.github.com/repos/monta-app/data-smart-charge/stargazers", - "statuses_url": "https://api.github.com/repos/monta-app/data-smart-charge/statuses/{sha}", - "subscribers_url": "https://api.github.com/repos/monta-app/data-smart-charge/subscribers", - "subscription_url": "https://api.github.com/repos/monta-app/data-smart-charge/subscription", - "svn_url": "https://github.com/monta-app/data-smart-charge", - "tags_url": "https://api.github.com/repos/monta-app/data-smart-charge/tags", - "teams_url": "https://api.github.com/repos/monta-app/data-smart-charge/teams", - "topics": [], - "trees_url": "https://api.github.com/repos/monta-app/data-smart-charge/git/trees{/sha}", - "updated_at": "2024-04-26T10:20:57Z", - "url": "https://api.github.com/repos/monta-app/data-smart-charge", - "visibility": "private", - "watchers": 1, - "watchers_count": 1, - "web_commit_signoff_required": false - }, - "sender": { - "avatar_url": "https://avatars.githubusercontent.com/u/63373006?v=4", - "events_url": "https://api.github.com/users/baldm/events{/privacy}", - "followers_url": "https://api.github.com/users/baldm/followers", - "following_url": "https://api.github.com/users/baldm/following{/other_user}", - "gists_url": "https://api.github.com/users/baldm/gists{/gist_id}", - "gravatar_id": "", - "html_url": "https://github.com/baldm", - "id": 63373006, - "login": "baldm", - "node_id": "MDQ6VXNlcjYzMzczMDA2", - "organizations_url": "https://api.github.com/users/baldm/orgs", - "received_events_url": "https://api.github.com/users/baldm/received_events", - "repos_url": "https://api.github.com/users/baldm/repos", - "site_admin": false, - "starred_url": "https://api.github.com/users/baldm/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/baldm/subscriptions", - "type": "User", - "url": "https://api.github.com/users/baldm" - } -} From 1652405cdc7ae58c4ea35cf27649bb96090a1103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Z=C3=B8rn?= Date: Tue, 30 Apr 2024 09:29:58 +0200 Subject: [PATCH 4/5] Remove annotations --- .../kotlin/com/monta/slack/notifier/util/FileUtils.kt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/util/FileUtils.kt b/src/commonMain/kotlin/com/monta/slack/notifier/util/FileUtils.kt index 235cc64..a4fab06 100644 --- a/src/commonMain/kotlin/com/monta/slack/notifier/util/FileUtils.kt +++ b/src/commonMain/kotlin/com/monta/slack/notifier/util/FileUtils.kt @@ -9,7 +9,6 @@ import kotlinx.cinterop.ExperimentalForeignApi import kotlinx.cinterop.allocArray import kotlinx.cinterop.memScoped import kotlinx.cinterop.toKString -import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerializationException import platform.posix.fclose import platform.posix.fgets @@ -45,7 +44,6 @@ fun populateEventFromJson(eventJson: String): BaseGithubContext { return populateOnJsonPush(eventJson) ?: populateOnJsonOpened(eventJson) ?: populateOnJsonCreated(eventJson) ?: handleFailure() } -@OptIn(ExperimentalSerializationApi::class) private fun populateOnJsonPush(eventJson: String): BaseGithubContext? { return try { val event = JsonUtil.instance.decodeFromString(eventJson) @@ -59,7 +57,6 @@ private fun populateOnJsonPush(eventJson: String): BaseGithubContext? { } } -@OptIn(ExperimentalSerializationApi::class) private fun populateOnJsonOpened(eventJson: String): BaseGithubContext? { return try { val event = JsonUtil.instance.decodeFromString(eventJson) @@ -73,7 +70,6 @@ private fun populateOnJsonOpened(eventJson: String): BaseGithubContext? { } } -@OptIn(ExperimentalSerializationApi::class) private fun populateOnJsonCreated(eventJson: String): BaseGithubContext? { return try { val event = JsonUtil.instance.decodeFromString(eventJson) From 6ea7f571d99bc9e0fdaa77eac5cd2f9d994c6de7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Z=C3=B8rn?= Date: Fri, 3 May 2024 12:36:04 +0200 Subject: [PATCH 5/5] Fixed detekt warning --- .../kotlin/com/monta/slack/notifier/util/FileUtils.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/util/FileUtils.kt b/src/commonMain/kotlin/com/monta/slack/notifier/util/FileUtils.kt index a4fab06..621c94e 100644 --- a/src/commonMain/kotlin/com/monta/slack/notifier/util/FileUtils.kt +++ b/src/commonMain/kotlin/com/monta/slack/notifier/util/FileUtils.kt @@ -45,6 +45,7 @@ fun populateEventFromJson(eventJson: String): BaseGithubContext { } private fun populateOnJsonPush(eventJson: String): BaseGithubContext? { + @Suppress("SwallowedException") return try { val event = JsonUtil.instance.decodeFromString(eventJson) return BaseGithubContext( @@ -58,6 +59,7 @@ private fun populateOnJsonPush(eventJson: String): BaseGithubContext? { } private fun populateOnJsonOpened(eventJson: String): BaseGithubContext? { + @Suppress("SwallowedException") return try { val event = JsonUtil.instance.decodeFromString(eventJson) return BaseGithubContext( @@ -71,6 +73,7 @@ private fun populateOnJsonOpened(eventJson: String): BaseGithubContext? { } private fun populateOnJsonCreated(eventJson: String): BaseGithubContext? { + @Suppress("SwallowedException") return try { val event = JsonUtil.instance.decodeFromString(eventJson) return BaseGithubContext(