Skip to content

Commit 09d306a

Browse files
feat:added welcome-first-time-contributor.yml
Signed-off-by: shiva <shiva_05@outlook.com>
1 parent 36bc401 commit 09d306a

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
2+
name: Welcome first time contributors
3+
4+
on:
5+
pull_request_target:
6+
types:
7+
- opened
8+
issues:
9+
types:
10+
- opened
11+
12+
jobs:
13+
welcome:
14+
name: Post welcome message
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/github-script@v7
18+
with:
19+
github-token: ${{ secrets.GITHUB_TOKEN }}
20+
script: |
21+
const issueMessage = `Welcome to Accord. Thanks a lot for reporting your first issue. Please check out our [contributors guide](https://github.com/accordproject/techdocs/blob/main/CONTRIBUTING.md) .<br />Keep in mind there are also other channels you can use to interact with Accord community. For more details check out [dicord](https://discord.com/invite/Zm99SKhhtA).`;
22+
const prMessage = `Welcome to Accord. Thanks a lot for reporting your first issue. Please check out our [contributors guide](https://github.com/accordproject/techdocs/blob/main/CONTRIBUTING.md) .<br />Keep in mind there are also other channels you can use to interact with Accord community. For more details check out [dicord](https://discord.com/invite/Zm99SKhhtA).`;
23+
if (!issueMessage && !prMessage) {
24+
throw new Error('Action must have at least one of issue-message or pr-message set');
25+
}
26+
const isIssue = !!context.payload.issue;
27+
let isFirstContribution;
28+
if (isIssue) {
29+
const query = `query($owner:String!, $name:String!, $contributer:String!) {
30+
repository(owner:$owner, name:$name){
31+
issues(first: 1, filterBy: {createdBy:$contributer}){
32+
totalCount
33+
}
34+
}
35+
}`;
36+
const variables = {
37+
owner: context.repo.owner,
38+
name: context.repo.repo,
39+
contributer: context.payload.sender.login
40+
};
41+
const { repository: { issues: { totalCount } } } = await github.graphql(query, variables);
42+
isFirstContribution = totalCount === 1;
43+
} else {
44+
const query = `query($qstr: String!) {
45+
search(query: $qstr, type: ISSUE, first: 1) {
46+
issueCount
47+
}
48+
}`;
49+
const variables = {
50+
"qstr": `repo:${context.repo.owner}/${context.repo.repo} type:pr author:${context.payload.sender.login}`,
51+
};
52+
const { search: { issueCount } } = await github.graphql(query, variables);
53+
isFirstContribution = issueCount === 1;
54+
}
55+
56+
if (!isFirstContribution) {
57+
console.log(`Not the users first contribution.`);
58+
return;
59+
}
60+
const message = isIssue ? issueMessage : prMessage;
61+
// Add a comment to the appropriate place
62+
if (isIssue) {
63+
const issueNumber = context.payload.issue.number;
64+
console.log(`Adding message: ${message} to issue #${issueNumber}`);
65+
await github.rest.issues.createComment({
66+
owner: context.payload.repository.owner.login,
67+
repo: context.payload.repository.name,
68+
issue_number: issueNumber,
69+
body: message
70+
});
71+
}
72+
else {
73+
const pullNumber = context.payload.pull_request.number;
74+
console.log(`Adding message: ${message} to pull request #${pullNumber}`);
75+
await github.rest.pulls.createReview({
76+
owner: context.payload.repository.owner.login,
77+
repo: context.payload.repository.name,
78+
pull_number: pullNumber,
79+
body: message,
80+
event: 'COMMENT'
81+
});
82+
}

0 commit comments

Comments
 (0)