-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
welcome-first-time-contrib.yml
83 lines (79 loc) · 4.01 KB
/
welcome-first-time-contrib.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#This action is centrally managed in https://github.com/asyncapi/.github/
#Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo
name: Welcome first time contributors
on:
pull_request_target:
types:
- opened
issues:
types:
- opened
jobs:
welcome:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issueMessage = `Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our [contributors guide](https://github.com/asyncapi/community/blob/master/CONTRIBUTING.md) and the instructions about a [basic recommended setup](https://github.com/asyncapi/.github/blob/master/git-workflow.md) useful for opening a pull request.<br />Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out [this issue](https://github.com/asyncapi/asyncapi/issues/115).`;
const prMessage = `Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our [contributors guide](https://github.com/asyncapi/community/blob/master/CONTRIBUTING.md) useful for opening a pull request.<br />Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out [this issue](https://github.com/asyncapi/asyncapi/issues/115).`;
if (!issueMessage && !prMessage) {
throw new Error('Action must have at least one of issue-message or pr-message set');
}
const isIssue = !!context.payload.issue;
let isFirstContribution;
if (isIssue) {
const query = `query($owner:String!, $name:String!, $contributer:String!) {
repository(owner:$owner, name:$name){
issues(first: 1, filterBy: {createdBy:$contributer}){
totalCount
}
}
}`;
const variables = {
owner: context.repo.owner,
name: context.repo.repo,
contributer: context.payload.sender.login
};
const { repository: { issues: { totalCount } } } = await github.graphql(query, variables);
isFirstContribution = totalCount === 1;
} else {
const query = `query($qstr: String!) {
search(query: $qstr, type: ISSUE, first: 1) {
issueCount
}
}`;
const variables = {
"qstr": `repo:${context.repo.owner}/${context.repo.repo} type:pr author:${context.payload.sender.login}`,
};
const { search: { issueCount } } = await github.graphql(query, variables);
isFirstContribution = issueCount === 1;
}
if (!isFirstContribution) {
console.log(`Not the users first contribution.`);
return;
}
const message = isIssue ? issueMessage : prMessage;
// Add a comment to the appropriate place
if (isIssue) {
const issueNumber = context.payload.issue.number;
console.log(`Adding message: ${message} to issue #${issueNumber}`);
await github.issues.createComment({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
issue_number: issueNumber,
body: message
});
}
else {
const pullNumber = context.payload.pull_request.number;
console.log(`Adding message: ${message} to pull request #${pullNumber}`);
await github.pulls.createReview({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
pull_number: pullNumber,
body: message,
event: 'COMMENT'
});
}