Skip to content

Commit

Permalink
tests: add cases that check repo-specific config loading behavior
Browse files Browse the repository at this point in the history
`push.multi_repo_custom_repo_secrets`
The correct repo-specific secrets configuration should be loaded
for the given payload repo.

`status.multi_repo_disallowed_repo`
If `allowed_repositories` excludes the payload repo, it should be
ignored.

`status.multi_repo_independent_status_state`
The status rules should be evaluated for the correct repo. In this
test case, it should correctly detect that `master`'s last build
status was a failure for the given payload repo, and issue a
success notification.
  • Loading branch information
yasunariw committed Dec 29, 2020
1 parent 753830d commit a3eea15
Show file tree
Hide file tree
Showing 11 changed files with 415 additions and 9 deletions.
14 changes: 14 additions & 0 deletions mock_config/push.multi_repo_custom_repo_secrets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"main_branch_name": "develop",
"status_rules": {
"rules": []
},
"prefix_rules": {
"default_channel": "default",
"rules": [{ "channel": "all-push-events" }]
},
"label_rules": {
"default_channel": "default",
"rules": []
}
}
113 changes: 113 additions & 0 deletions mock_payloads/push.multi_repo_custom_repo_secrets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{
"ref": "refs/heads/master",
"before": "fb245e2a6d52d10025c8bd4f36f6e3134d85ae18",
"after": "e2173f38ae43865433a182c1fc1b5442d9763b54",
"created": false,
"deleted": false,
"forced": false,
"base_ref": null,
"compare": "https://github.com/acme/runner/compare/fb245e2a6d52...e2173f38ae43",
"commits": [
{
"id": "80452f696a8988e7234063d47720a62e902f2afc",
"tree_id": "bf7530bb0b13d0b9f471ff5d1951c59488b5704c",
"distinct": true,
"message": "Update readme",
"timestamp": "2019-07-06T11:47:56+01:00",
"url": "https://github.com/acme/runner/commit/80452f696a8988e7234063d47720a62e902f2afc",
"author": {
"name": "wile e coyote",
"email": "[email protected]",
"username": "wileecoyote"
},
"committer": {
"name": "wile e coyote",
"email": "[email protected]",
"username": "wileecoyote"
},
"added": [],
"removed": [],
"modified": [
"README.md"
]
},
{
"id": "e2173f38ae43865433a182c1fc1b5442d9763b54",
"tree_id": "6dc065fdfacfc72cd7b1f5e7a9391c238e4fb74e",
"distinct": true,
"message": "Add TESTING.md",
"timestamp": "2019-07-06T11:48:38+01:00",
"url": "https://github.com/acme/runner/commit/e2173f38ae43865433a182c1fc1b5442d9763b54",
"author": {
"name": "wile e coyote",
"email": "[email protected]",
"username": "wileecoyote"
},
"committer": {
"name": "wile e coyote",
"email": "[email protected]",
"username": "wileecoyote"
},
"added": [
"TESTING.md",
"backend/api/longest/test.ml"
],
"removed": [],
"modified": []
}
],
"head_commit": {
"id": "e2173f38ae43865433a182c1fc1b5442d9763b54",
"tree_id": "6dc065fdfacfc72cd7b1f5e7a9391c238e4fb74e",
"distinct": true,
"message": "Add TESTING.md",
"timestamp": "2019-07-06T11:48:38+01:00",
"url": "https://github.com/acme/runner/commit/e2173f38ae43865433a182c1fc1b5442d9763b54",
"author": {
"name": "wile e coyote",
"email": "[email protected]",
"username": "wileecoyote"
},
"committer": {
"name": "wile e coyote",
"email": "[email protected]",
"username": "wileecoyote"
},
"added": [
"TESTING.md"
],
"removed": [],
"modified": []
},
"pusher": {
"name": "wileecoyote",
"email": "[email protected]"
},
"sender": {
"login": "wileecoyote",
"id": 8755205,
"node_id": "MDQ6VXNlcjg3NTUyMDU=",
"avatar_url": "https://avatars1.githubusercontent.com/u/8755205?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/wileecoyote",
"html_url": "https://github.com/wileecoyote",
"followers_url": "https://api.github.com/users/wileecoyote/followers",
"following_url": "https://api.github.com/users/wileecoyote/following{/other_user}",
"gists_url": "https://api.github.com/users/wileecoyote/gists{/gist_id}",
"starred_url": "https://api.github.com/users/wileecoyote/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/wileecoyote/subscriptions",
"organizations_url": "https://api.github.com/users/wileecoyote/orgs",
"repos_url": "https://api.github.com/users/wileecoyote/repos",
"events_url": "https://api.github.com/users/wileecoyote/events{/privacy}",
"received_events_url": "https://api.github.com/users/wileecoyote/received_events",
"type": "User",
"site_admin": false
},
"repository": {
"name": "runner",
"full_name": "acme/runner",
"html_url": "https://github.com/acme/runner",
"contents_url": "https://api.github.com/repos/acme/runner/contents/{+path}",
"commits_url": "https://api.github.com/repos/acme/runner/commits{/sha}"
}
}
84 changes: 84 additions & 0 deletions mock_payloads/status.multi_repo_disallowed_repo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"sha": "0d95302addd66c1816bce1b1d495ed1c93ccd478",
"context": "buildkite/notabot-test/build",
"state": "pending",
"commit": {
"sha": "0d95302addd66c1816bce1b1d495ed1c93ccd478",
"node_id": "MDY6Q29tbWl0MTgyOjBkOTUzMDJhZGRkNjZjMTgxNmJjZTFiMWQ0OTVlZDFjOTNjY2Q0Nzg=",
"commit": {
"author": {
"name": "Louis Roché",
"email": "[email protected]",
"date": "2020-06-02T03:14:51Z"
},
"committer": {
"name": "GitHub Enterprise",
"email": "[email protected]",
"date": "2020-06-02T03:14:51Z"
},
"message": "Update README.md",
"tree": {
"sha": "ee5c539cad37c77348ce7a55756acc542b41cfc7",
"url": "https://git.ahrefs.com/api/v3/repos/ahrefs/notabot_test/git/trees/ee5c539cad37c77348ce7a55756acc542b41cfc7"
},
"url": "https://git.ahrefs.com/api/v3/repos/ahrefs/notabot_test/git/commits/0d95302addd66c1816bce1b1d495ed1c93ccd478",
"comment_count": 0,
"verification": {
"verified": false,
"reason": "unsigned",
"signature": null,
"payload": null
}
},
"url": "https://git.ahrefs.com/api/v3/repos/ahrefs/notabot_test/commits/0d95302addd66c1816bce1b1d495ed1c93ccd478",
"html_url": "https://git.ahrefs.com/ahrefs/notabot_test/commit/0d95302addd66c1816bce1b1d495ed1c93ccd478",
"comments_url": "https://git.ahrefs.com/api/v3/repos/ahrefs/notabot_test/commits/0d95302addd66c1816bce1b1d495ed1c93ccd478/comments",
"author": {
"login": "louis",
"id": 34,
"node_id": "MDQ6VXNlcjM0",
"avatar_url": "https://git.ahrefs.com/avatars/u/34?",
"gravatar_id": "",
"url": "https://git.ahrefs.com/api/v3/users/louis",
"html_url": "https://git.ahrefs.com/louis",
"followers_url": "https://git.ahrefs.com/api/v3/users/louis/followers",
"following_url": "https://git.ahrefs.com/api/v3/users/louis/following{/other_user}",
"gists_url": "https://git.ahrefs.com/api/v3/users/louis/gists{/gist_id}",
"starred_url": "https://git.ahrefs.com/api/v3/users/louis/starred{/owner}{/repo}",
"subscriptions_url": "https://git.ahrefs.com/api/v3/users/louis/subscriptions",
"organizations_url": "https://git.ahrefs.com/api/v3/users/louis/orgs",
"repos_url": "https://git.ahrefs.com/api/v3/users/louis/repos",
"events_url": "https://git.ahrefs.com/api/v3/users/louis/events{/privacy}",
"received_events_url": "https://git.ahrefs.com/api/v3/users/louis/received_events",
"type": "User",
"site_admin": false
},
"committer": null,
"parents": [
{
"sha": "04cb72d6dc8d92131282a7eff57f6caf632f0a39",
"url": "https://git.ahrefs.com/api/v3/repos/ahrefs/notabot_test/commits/04cb72d6dc8d92131282a7eff57f6caf632f0a39",
"html_url": "https://git.ahrefs.com/ahrefs/notabot_test/commit/04cb72d6dc8d92131282a7eff57f6caf632f0a39"
}
]
},
"branches": [
{
"name": "master",
"commit": {
"sha": "0d95302addd66c1816bce1b1d495ed1c93ccd478",
"url": "https://git.ahrefs.com/api/v3/repos/ahrefs/notabot_test/commits/0d95302addd66c1816bce1b1d495ed1c93ccd478"
},
"protected": false
}
],
"created_at": "2020-06-02T03:20:35+00:00",
"updated_at": "2020-06-02T03:20:35+00:00",
"repository": {
"name": "runner",
"full_name": "acme/runner",
"html_url": "https://github.com/acme/runner",
"contents_url": "https://api.github.com/repos/acme/runner/contents/{+path}",
"commits_url": "https://api.github.com/repos/acme/runner/commits{/sha}"
}
}
97 changes: 97 additions & 0 deletions mock_payloads/status.multi_repo_independent_status_state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"id": 1437427,
"sha": "0d95302addd66c1816bce1b1d495ed1c93ccd478",
"name": "ahrefs/notabot_test",
"target_url": "https://buildkite.com/ahrefs/notabot-test/builds/2",
"avatar_url": "https://git.ahrefs.com/avatars/oa/6?",
"context": "buildkite/notabot-test",
"description": "Build #2 passed (5 minutes, 19 seconds)",
"state": "success",
"commit": {
"sha": "0d95302addd66c1816bce1b1d495ed1c93ccd478",
"node_id": "MDY6Q29tbWl0MTgyOjBkOTUzMDJhZGRkNjZjMTgxNmJjZTFiMWQ0OTVlZDFjOTNjY2Q0Nzg=",
"commit": {
"author": {
"name": "Louis Roché",
"email": "[email protected]",
"date": "2020-06-02T03:14:51Z"
},
"committer": {
"name": "GitHub Enterprise",
"email": "[email protected]",
"date": "2020-06-02T03:14:51Z"
},
"message": "Update README.md",
"tree": {
"sha": "ee5c539cad37c77348ce7a55756acc542b41cfc7",
"url": "https://git.ahrefs.com/api/v3/repos/ahrefs/notabot_test/git/trees/ee5c539cad37c77348ce7a55756acc542b41cfc7"
},
"url": "https://git.ahrefs.com/api/v3/repos/ahrefs/notabot_test/git/commits/0d95302addd66c1816bce1b1d495ed1c93ccd478",
"comment_count": 0,
"verification": {
"verified": false,
"reason": "unsigned",
"signature": null,
"payload": null
}
},
"url": "https://git.ahrefs.com/api/v3/repos/ahrefs/notabot_test/commits/0d95302addd66c1816bce1b1d495ed1c93ccd478",
"html_url": "https://git.ahrefs.com/ahrefs/notabot_test/commit/0d95302addd66c1816bce1b1d495ed1c93ccd478",
"comments_url": "https://git.ahrefs.com/api/v3/repos/ahrefs/notabot_test/commits/0d95302addd66c1816bce1b1d495ed1c93ccd478/comments",
"author": {
"login": "louis",
"id": 34,
"node_id": "MDQ6VXNlcjM0",
"avatar_url": "https://git.ahrefs.com/avatars/u/34?",
"gravatar_id": "",
"url": "https://git.ahrefs.com/api/v3/users/louis",
"html_url": "https://git.ahrefs.com/louis",
"followers_url": "https://git.ahrefs.com/api/v3/users/louis/followers",
"following_url": "https://git.ahrefs.com/api/v3/users/louis/following{/other_user}",
"gists_url": "https://git.ahrefs.com/api/v3/users/louis/gists{/gist_id}",
"starred_url": "https://git.ahrefs.com/api/v3/users/louis/starred{/owner}{/repo}",
"subscriptions_url": "https://git.ahrefs.com/api/v3/users/louis/subscriptions",
"organizations_url": "https://git.ahrefs.com/api/v3/users/louis/orgs",
"repos_url": "https://git.ahrefs.com/api/v3/users/louis/repos",
"events_url": "https://git.ahrefs.com/api/v3/users/louis/events{/privacy}",
"received_events_url": "https://git.ahrefs.com/api/v3/users/louis/received_events",
"type": "User",
"site_admin": false
},
"committer": null,
"parents": [
{
"sha": "04cb72d6dc8d92131282a7eff57f6caf632f0a39",
"url": "https://git.ahrefs.com/api/v3/repos/ahrefs/notabot_test/commits/04cb72d6dc8d92131282a7eff57f6caf632f0a39",
"html_url": "https://git.ahrefs.com/ahrefs/notabot_test/commit/04cb72d6dc8d92131282a7eff57f6caf632f0a39"
}
]
},
"branches": [
{
"name": "master",
"commit": {
"sha": "0d95302addd66c1816bce1b1d495ed1c93ccd478",
"url": "https://git.ahrefs.com/api/v3/repos/ahrefs/notabot_test/commits/0d95302addd66c1816bce1b1d495ed1c93ccd478"
},
"protected": false
}
],
"created_at": "2020-06-02T03:21:39+00:00",
"updated_at": "2020-06-02T03:21:39+00:00",
"repository": {
"id": 182,
"node_id": "MDEwOlJlcG9zaXRvcnkxODI=",
"name": "notabot_test",
"full_name": "ahrefs/notabot_test",
"private": true,
"html_url": "https://git.ahrefs.com/ahrefs/notabot_test",
"description": null,
"fork": false,
"commits_url": "https://git.ahrefs.com/api/v3/repos/ahrefs/notabot_test/commits{/sha}",
"contents_url": "https://git.ahrefs.com/api/v3/repos/ahrefs/notabot_test/contents/{+path}",
"created_at": "2020-06-01T18:44:17Z",
"updated_at": "2020-06-02T03:14:53Z",
"pushed_at": "2020-06-02T03:14:51Z"
}
}
17 changes: 17 additions & 0 deletions mock_secrets/push.multi_repo_custom_repo_secrets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"repositories": {
"https://github.com/acme/runner": {
"gh_token": "XXX"
},
"https://git.ahrefs.com/ahrefs/notabot_test": {
"gh_token": "XXX",
"gh_hook_token": "XXX"
}
},
"slack_hooks": [
{
"url": "https://slack_webhook_url",
"channel": "all-push-events"
}
]
}
4 changes: 4 additions & 0 deletions mock_secrets/status.multi_repo_disallowed_repo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"allowed_repositories": ["https://git.ahrefs.com/ahrefs/notabot_test"],
"slack_hooks": []
}
16 changes: 16 additions & 0 deletions mock_states/status.multi_repo_independent_status_state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"https://github.com/acme/runner": {
"pipeline_statuses": {
"buildkite/notabot-test": {
"master": "success"
}
}
},
"https://git.ahrefs.com/ahrefs/notabot_test": {
"pipeline_statuses": {
"buildkite/notabot-test": {
"master": "failure"
}
}
}
}
3 changes: 1 addition & 2 deletions mock_states/status.state_hide_success_test.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"https://git.ahrefs.com/ahrefs/notabot_test": {
"pipeline_statuses": {
Expand All @@ -10,4 +9,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
}
}
}
}
}
Loading

0 comments on commit a3eea15

Please sign in to comment.