Skip to content

Commit bb169fe

Browse files
gagoarcyamonide
andauthored
adding targetURL when using status action (#118)
* adding targetURL when using `status` action * spelling * adding validation link to the wiki * allowing targetURL to be passed in the rules * Update README.md Co-authored-by: Simon Liu <cyamonide@gmail.com> * adding link for Description validation * proper link * Update herald_rules/validate_description_is_present.json Co-authored-by: Simon Liu <cyamonide@gmail.com> * Update herald_rules/validate_issue_is_present.json Co-authored-by: Simon Liu <cyamonide@gmail.com>
1 parent a36bcd5 commit bb169fe

File tree

8 files changed

+66
-11
lines changed

8 files changed

+66
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Every rule can be written in JSON with the following key-value pairs:
8585
| `customMessage` | `string` | No | Message to be commented on the pull request when the rule is applied (requires `action === comment`) |
8686
| `users` | `string[]` | No | GitHub user handles (or emails) on which the rule will take action. It will not be used when `action` is set to `comment` and `customMessage` field is present |
8787
| `teams` | `string[]` | No | GitHub teams on which the rule will take action. It will not be used when `action` is set to `comment` and `customMessage` field is present |
88+
| `targetURL` | `string` | No | When `action` set to `status`, link to which the [Details](https://github.blog/2012-09-04-commit-status-api/) link will point |
8889
| `labels` | `string[]` | No | Github labels which the rule will add. Only valid when `action` field is set to `label` |
8990
| `errorLevel` | `string` | No | Currently, supported error levels are `none`, `error`, by default is set to `none`, you can read more [here](#error-levels) |
9091

__tests__/statuses.spec.ts

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ describe('handleReviewers', () => {
3838
glob: '*.js',
3939
};
4040

41+
const rule3 = {
42+
...rule,
43+
path: `${env.GITHUB_WORKSPACE}/rules/rule2.json`,
44+
targetURL: 'http://some/link',
45+
name: 'it should have js files in the PR',
46+
glob: '*.js',
47+
};
4148
beforeEach(() => {
4249
nock.cleanAll();
4350
});
@@ -57,6 +64,13 @@ describe('handleReviewers', () => {
5764
cb(null, { ...createStatusRequest, target_url, description, state, context });
5865
});
5966

67+
github
68+
.post(`/repos/${owner}/${repo}/statuses/${sha}`)
69+
.reply(201, (_uri, body: { target_url: string; description: string; state: string; context: string }, cb) => {
70+
const { target_url, description, state, context } = body;
71+
cb(null, { ...createStatusRequest, target_url, description, state, context });
72+
});
73+
6074
const files = [
6175
{
6276
filename: 'rules/rule.json',
@@ -70,7 +84,7 @@ describe('handleReviewers', () => {
7084
repo,
7185
prNumber,
7286
matchingRules: [{ ...rule, matched: true }],
73-
rules: [rule, rule2],
87+
rules: [rule, rule2, rule3],
7488
sha,
7589
base: '6dcb09b5b57875f334f61aebed695e2e4193d111',
7690
files,
@@ -156,6 +170,45 @@ describe('handleReviewers', () => {
156170
"status": 201,
157171
"url": "https://api.github.com/repos/gagoar/example_repo/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e",
158172
},
173+
Object {
174+
"data": Object {
175+
"avatar_url": "https://github.com/images/error/hubot_happy.gif",
176+
"context": "Herald/it should have js files in the PR",
177+
"created_at": "2012-07-20T01:19:13Z",
178+
"creator": Object {
179+
"avatar_url": "https://github.com/images/error/gagoar_happy.gif",
180+
"events_url": "https://api.github.com/users/gagoar/events{/privacy}",
181+
"followers_url": "https://api.github.com/users/gagoar/followers",
182+
"following_url": "https://api.github.com/users/gagoar/following{/other_user}",
183+
"gists_url": "https://api.github.com/users/gagoar/gists{/gist_id}",
184+
"gravatar_id": "",
185+
"html_url": "https://github.com/gagoar",
186+
"id": 1,
187+
"login": "gagoar",
188+
"node_id": "MDQ6VXNlcjE=",
189+
"organizations_url": "https://api.github.com/users/gagoar/orgs",
190+
"received_events_url": "https://api.github.com/users/gagoar/received_events",
191+
"repos_url": "https://api.github.com/users/gagoar/repos",
192+
"site_admin": false,
193+
"starred_url": "https://api.github.com/users/gagoar/starred{/owner}{/repo}",
194+
"subscriptions_url": "https://api.github.com/users/gagoar/subscriptions",
195+
"type": "User",
196+
"url": "https://api.github.com/users/gagoar",
197+
},
198+
"description": "You can see the rule by clicking on Details",
199+
"id": 1,
200+
"node_id": "MDY6U3RhdHVzMQ==",
201+
"state": "failure",
202+
"target_url": "http://some/link",
203+
"updated_at": "2012-07-20T01:19:13Z",
204+
"url": "https://api.github.com/repos/gagoar/example_repo/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e",
205+
},
206+
"headers": Object {
207+
"content-type": "application/json",
208+
},
209+
"status": 201,
210+
"url": "https://api.github.com/repos/gagoar/example_repo/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e",
211+
},
159212
]
160213
`);
161214
expect(github.isDone()).toBe(true);

dist/index.js

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/src/rules.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface Rule {
2323
customMessage?: string;
2424
labels?: string[];
2525
description?: string;
26+
targetURL?: string;
2627
errorLevel?: keyof typeof ErrorLevels;
2728
}
2829
export declare const loadRules: (rulesLocation: string) => Rule[];
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "The template has a Description",
3+
"targetURL": "https://github.com/gagoar/use-herald-action/wiki/PR-Validations#validate-description-title-is-present",
34
"action": "status",
45
"eventJsonPath": ["$[?(@.body.match(/## Description/i))].body"]
56
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "The template has an issue attached",
3-
"description": "Check if an issue present on PR",
3+
"description": "Check if an issue is present on PR",
4+
"targetURL": "https://github.com/gagoar/use-herald-action/wiki/PR-Validations#validate-if-the-issue-is-present-in-the-prs-description",
45
"action": "status",
56
"eventJsonPath": ["$[?(@.body.match(/Issue Reference.+#[0-9]+/i))].body"]
67
}

src/rules.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ enum RuleExtras {
3131
customMessage = 'customMessage',
3232
name = 'name',
3333
errorLevel = 'errorLevel',
34-
3534
labels = 'labels',
36-
3735
description = 'description',
36+
targetURL = 'targetURL',
3837
}
3938
enum RuleMatchers {
4039
includesInPatch = 'includesInPatch',
@@ -70,11 +69,9 @@ export interface Rule {
7069
includesInPatch?: string[];
7170
eventJsonPath?: string[];
7271
customMessage?: string;
73-
7472
labels?: string[];
75-
7673
description?: string;
77-
74+
targetURL?: string;
7875
errorLevel?: keyof typeof ErrorLevels;
7976
}
8077

src/statuses.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ export const handleStatus: ActionMapInput = async (
3333
owner,
3434
repo,
3535
sha,
36-
description: rule.description ? rule.description : STATUS_DESCRIPTION_COPY,
3736
context: `Herald/${rule.name}`,
38-
target_url: getBlobURL(rule.path, files, baseBlobPath, base),
37+
description: rule.description ? rule.description : STATUS_DESCRIPTION_COPY,
38+
target_url: rule.targetURL ? rule.targetURL : getBlobURL(rule.path, files, baseBlobPath, base),
3939
state: matchingRules.find((matchingRule) => matchingRule.path === rule.path)
4040
? CommitStatus.SUCCESS
4141
: CommitStatus.FAILURE,

0 commit comments

Comments
 (0)