Skip to content

Commit

Permalink
github: support missing author in status notification
Browse files Browse the repository at this point in the history
  • Loading branch information
Khady committed Jul 11, 2024
1 parent 1f89e6b commit 9ae19af
Show file tree
Hide file tree
Showing 3 changed files with 237 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/github.atd
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ type status_commit = {
sha: commit_hash;
commit: inner_commit;
url: string;
author: github_user;
?author: github_user option; (* will be none if author's email is not associated with any github account *)
html_url: string;
}

Expand Down
10 changes: 9 additions & 1 deletion lib/slack.ml
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,15 @@ let generate_status_notification (cfg : Config_t.config) (notification : status_
Some (sprintf "*Description*: %s." text)
in
let commit_info =
[ sprintf "*Commit*: `<%s|%s>` %s - %s" html_url (git_short_sha_hash sha) (first_line message) author.login ]
[
sprintf "*Commit*: `<%s|%s>` %s - %s" html_url (git_short_sha_hash sha) (first_line message)
((* If the author's email is not associated with a github account the author will be missing.
Using the information from the commit instead, which should be equivalent. *)
Option.map_default
(fun { login; _ } -> login)
commit.author.name author
);
]
in
let branches_info =
match List.map (fun ({ name } : branch) -> name) notification.branches with
Expand Down
227 changes: 227 additions & 0 deletions mock_payloads/status.missing_author.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
{
"id": 0,
"sha": "2129f69a03641c39dfeb8e928cc08d7a8d029c6b",
"name": "ahrefs/monorepo",
"target_url": "https://buildkite.com/ahrefs/monorepo-extra/builds/23670",
"avatar_url": "https://github.com/avatars/oa/0",
"context": "buildkite/pipeline1",
"description": "Build #23670 canceled by Max",
"state": "failure",
"commit": {
"sha": "2129f69a03641c39dfeb8e928cc08d7a8d029c6b",
"node_id": "00000000000000000000",
"commit": {
"author": {
"name": "yasunariw",
"email": "[email protected]",
"date": "2020-06-26T03:40:28Z"
},
"committer": {
"name": "yasunariw",
"email": "[email protected]",
"date": "2020-06-26T03:40:28Z"
},
"message": "Merge branch 'develop' into feature/f2",
"tree": {
"sha": "c0357c3f40aae6bbc57aac50fd4a990873cf11e7",
"url": "https://github.com/api/v3/repos/ahrefs/monorepo/git/trees/c0357c3f40aae6bbc57aac50fd4a990873cf11e7"
},
"url": "https://github.com/api/v3/repos/ahrefs/monorepo/git/commits/2129f69a03641c39dfeb8e928cc08d7a8d029c6b",
"comment_count": 0,
"verification": {
"verified": true,
"reason": "valid",
"signature": "",
"payload": "tree c0357c3f40aae6bbc57aac50fd4a990873cf11e7\nparent ea432dabb762ea76bddcfc04aca6af20df9cb68b\nparent f8fd6e2f4198546182fd7b7e5498fe3c07fc272b\nauthor yasunariw <[email protected]> 1593142828 +0800\ncommitter yasunariw <[email protected]> 1593142828 +0800\n\nMerge branch 'develop' into feature/f2\n"
}
},
"url": "https://github.com/api/v3/repos/ahrefs/monorepo/commits/2129f69a03641c39dfeb8e928cc08d7a8d029c6b",
"html_url": "https://github.com/ahrefs/monorepo/commit/2129f69a03641c39dfeb8e928cc08d7a8d029c6b",
"comments_url": "https://github.com/api/v3/repos/ahrefs/monorepo/commits/2129f69a03641c39dfeb8e928cc08d7a8d029c6b/comments",
"author": null,
"committer": {
"login": "yasunariw",
"id": 0,
"node_id": "00000000000000000000",
"avatar_url": "https://github.com/avatars/u/0",
"gravatar_id": "",
"url": "https://github.com/api/v3/users/yasunariw",
"html_url": "https://github.com/yasunariw",
"followers_url": "https://github.com/api/v3/users/yasunariw/followers",
"following_url": "https://github.com/api/v3/users/yasunariw/following{/other_user}",
"gists_url": "https://github.com/api/v3/users/yasunariw/gists{/gist_id}",
"starred_url": "https://github.com/api/v3/users/yasunariw/starred{/owner}{/repo}",
"subscriptions_url": "https://github.com/api/v3/users/yasunariw/subscriptions",
"organizations_url": "https://github.com/api/v3/users/yasunariw/orgs",
"repos_url": "https://github.com/api/v3/users/yasunariw/repos",
"events_url": "https://github.com/api/v3/users/yasunariw/events{/privacy}",
"received_events_url": "https://github.com/api/v3/users/yasunariw/received_events",
"type": "User",
"site_admin": false
},
"parents": [
{
"sha": "ea432dabb762ea76bddcfc04aca6af20df9cb68b",
"url": "https://github.com/api/v3/repos/ahrefs/monorepo/commits/ea432dabb762ea76bddcfc04aca6af20df9cb68b",
"html_url": "https://github.com/ahrefs/monorepo/commit/ea432dabb762ea76bddcfc04aca6af20df9cb68b"
},
{
"sha": "f8fd6e2f4198546182fd7b7e5498fe3c07fc272b",
"url": "https://github.com/api/v3/repos/ahrefs/monorepo/commits/f8fd6e2f4198546182fd7b7e5498fe3c07fc272b",
"html_url": "https://github.com/ahrefs/monorepo/commit/f8fd6e2f4198546182fd7b7e5498fe3c07fc272b"
}
]
},
"branches": [
{
"name": "feature/f2",
"commit": {
"sha": "22628bb61cd3af359b730cb9addbe33a0b3c17f7",
"url": "https://github.com/api/v3/repos/ahrefs/monorepo/commits/22628bb61cd3af359b730cb9addbe33a0b3c17f7"
},
"protected": false
}
],
"created_at": "2020-06-26T03:45:27+00:00",
"updated_at": "2020-06-26T03:45:27+00:00",
"repository": {
"id": 0,
"node_id": "00000000000000000000",
"name": "monorepo",
"full_name": "ahrefs/monorepo",
"private": true,
"owner": {
"login": "ahrefs",
"id": 0,
"node_id": "00000000000000000000",
"avatar_url": "https://github.com/avatars/u/0",
"gravatar_id": "",
"url": "https://github.com/api/v3/users/ahrefs",
"html_url": "https://github.com/ahrefs",
"followers_url": "https://github.com/api/v3/users/ahrefs/followers",
"following_url": "https://github.com/api/v3/users/ahrefs/following{/other_user}",
"gists_url": "https://github.com/api/v3/users/ahrefs/gists{/gist_id}",
"starred_url": "https://github.com/api/v3/users/ahrefs/starred{/owner}{/repo}",
"subscriptions_url": "https://github.com/api/v3/users/ahrefs/subscriptions",
"organizations_url": "https://github.com/api/v3/users/ahrefs/orgs",
"repos_url": "https://github.com/api/v3/users/ahrefs/repos",
"events_url": "https://github.com/api/v3/users/ahrefs/events{/privacy}",
"received_events_url": "https://github.com/api/v3/users/ahrefs/received_events",
"type": "Organization",
"site_admin": false
},
"html_url": "https://github.com/ahrefs/monorepo",
"description": "Test repository",
"fork": false,
"url": "https://github.com/api/v3/repos/ahrefs/monorepo",
"forks_url": "https://github.com/api/v3/repos/ahrefs/monorepo/forks",
"keys_url": "https://github.com/api/v3/repos/ahrefs/monorepo/keys{/key_id}",
"collaborators_url": "https://github.com/api/v3/repos/ahrefs/monorepo/collaborators{/collaborator}",
"teams_url": "https://github.com/api/v3/repos/ahrefs/monorepo/teams",
"hooks_url": "https://github.com/api/v3/repos/ahrefs/monorepo/hooks",
"issue_events_url": "https://github.com/api/v3/repos/ahrefs/monorepo/issues/events{/number}",
"events_url": "https://github.com/api/v3/repos/ahrefs/monorepo/events",
"assignees_url": "https://github.com/api/v3/repos/ahrefs/monorepo/assignees{/user}",
"branches_url": "https://github.com/api/v3/repos/ahrefs/monorepo/branches{/branch}",
"tags_url": "https://github.com/api/v3/repos/ahrefs/monorepo/tags",
"blobs_url": "https://github.com/api/v3/repos/ahrefs/monorepo/git/blobs{/sha}",
"git_tags_url": "https://github.com/api/v3/repos/ahrefs/monorepo/git/tags{/sha}",
"git_refs_url": "https://github.com/api/v3/repos/ahrefs/monorepo/git/refs{/sha}",
"trees_url": "https://github.com/api/v3/repos/ahrefs/monorepo/git/trees{/sha}",
"statuses_url": "https://github.com/api/v3/repos/ahrefs/monorepo/statuses/{sha}",
"languages_url": "https://github.com/api/v3/repos/ahrefs/monorepo/languages",
"stargazers_url": "https://github.com/api/v3/repos/ahrefs/monorepo/stargazers",
"contributors_url": "https://github.com/api/v3/repos/ahrefs/monorepo/contributors",
"subscribers_url": "https://github.com/api/v3/repos/ahrefs/monorepo/subscribers",
"subscription_url": "https://github.com/api/v3/repos/ahrefs/monorepo/subscription",
"commits_url": "https://github.com/api/v3/repos/ahrefs/monorepo/commits{/sha}",
"git_commits_url": "https://github.com/api/v3/repos/ahrefs/monorepo/git/commits{/sha}",
"comments_url": "https://github.com/api/v3/repos/ahrefs/monorepo/comments{/number}",
"issue_comment_url": "https://github.com/api/v3/repos/ahrefs/monorepo/issues/comments{/number}",
"contents_url": "https://github.com/api/v3/repos/ahrefs/monorepo/contents/{+path}",
"compare_url": "https://github.com/api/v3/repos/ahrefs/monorepo/compare/{base}...{head}",
"merges_url": "https://github.com/api/v3/repos/ahrefs/monorepo/merges",
"archive_url": "https://github.com/api/v3/repos/ahrefs/monorepo/{archive_format}{/ref}",
"downloads_url": "https://github.com/api/v3/repos/ahrefs/monorepo/downloads",
"issues_url": "https://github.com/api/v3/repos/ahrefs/monorepo/issues{/number}",
"pulls_url": "https://github.com/api/v3/repos/ahrefs/monorepo/pulls{/number}",
"milestones_url": "https://github.com/api/v3/repos/ahrefs/monorepo/milestones{/number}",
"notifications_url": "https://github.com/api/v3/repos/ahrefs/monorepo/notifications{?since,all,participating}",
"labels_url": "https://github.com/api/v3/repos/ahrefs/monorepo/labels{/name}",
"releases_url": "https://github.com/api/v3/repos/ahrefs/monorepo/releases{/id}",
"deployments_url": "https://github.com/api/v3/repos/ahrefs/monorepo/deployments",
"created_at": "2017-03-06T23:40:04Z",
"updated_at": "2020-06-26T01:08:38Z",
"pushed_at": "2020-06-26T03:45:13Z",
"git_url": "git://github.com/ahrefs/monorepo.git",
"ssh_url": "[email protected]:ahrefs/monorepo.git",
"clone_url": "https://github.com/ahrefs/monorepo.git",
"svn_url": "https://github.com/ahrefs/monorepo",
"homepage": "https://ahrefs.com",
"size": 0,
"stargazers_count": 0,
"watchers_count": 0,
"language": "HTML",
"has_issues": true,
"has_projects": false,
"has_downloads": true,
"has_wiki": true,
"has_pages": false,
"forks_count": 0,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 0,
"license": null,
"forks": 0,
"open_issues": 0,
"watchers": 0,
"default_branch": "develop"
},
"organization": {
"login": "ahrefs",
"id": 0,
"node_id": "00000000000000000000",
"url": "https://github.com/api/v3/orgs/ahrefs",
"repos_url": "https://github.com/api/v3/orgs/ahrefs/repos",
"events_url": "https://github.com/api/v3/orgs/ahrefs/events",
"hooks_url": "https://github.com/api/v3/orgs/ahrefs/hooks",
"issues_url": "https://github.com/api/v3/orgs/ahrefs/issues",
"members_url": "https://github.com/api/v3/orgs/ahrefs/members{/member}",
"public_members_url": "https://github.com/api/v3/orgs/ahrefs/public_members{/member}",
"avatar_url": "https://github.com/avatars/u/0",
"description": null
},
"enterprise": {
"id": 0,
"slug": "ahrefs-pte-ltd",
"name": "Ahrefs Pte Ltd",
"node_id": "00000000000000000000",
"avatar_url": "https://github.com/avatars/b/0",
"description": null,
"website_url": null,
"html_url": "https://github.com/enterprises/ahrefs-pte-ltd",
"created_at": "2019-01-09T18:50:55Z",
"updated_at": "2019-03-01T16:07:28Z"
},
"sender": {
"login": "ygrek",
"id": 0,
"node_id": "00000000000000000000",
"avatar_url": "https://github.com/avatars/u/0",
"gravatar_id": "",
"url": "https://github.com/api/v3/users/ygrek",
"html_url": "https://github.com/ip",
"followers_url": "https://github.com/api/v3/users/ygrek/followers",
"following_url": "https://github.com/api/v3/users/ygrek/following{/other_user}",
"gists_url": "https://github.com/api/v3/users/ygrek/gists{/gist_id}",
"starred_url": "https://github.com/api/v3/users/ygrek/starred{/owner}{/repo}",
"subscriptions_url": "https://github.com/api/v3/users/ygrek/subscriptions",
"organizations_url": "https://github.com/api/v3/users/ygrek/orgs",
"repos_url": "https://github.com/api/v3/users/ygrek/repos",
"events_url": "https://github.com/api/v3/users/ygrek/events{/privacy}",
"received_events_url": "https://github.com/api/v3/users/ygrek/received_events",
"type": "User",
"site_admin": true
}
}

0 comments on commit 9ae19af

Please sign in to comment.