Skip to content

Commit 41fc261

Browse files
committed
feat: add add loabl
1 parent bdfb100 commit 41fc261

File tree

4 files changed

+67
-38
lines changed

4 files changed

+67
-38
lines changed

.github/github-action/action.yml

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
name: 'Hello World'
22
description: 'Greet someone and record the time'
33
inputs:
4-
who-to-greet: # id of input
5-
description: 'Who to greet'
6-
required: true
7-
default: 'World'
8-
outputs:
9-
time: # id of output
10-
description: 'The time we greeted you'
4+
github_token:
5+
description: A GitHub token.
6+
required: false
7+
default: ${{ github.token }}
118
runs:
129
using: 'node20'
1310
main: 'index.js'

.github/github-action/contributors.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const contributors = [
2+
'tomalaforge',
3+
'alcaidio',
4+
'svenson95',
5+
'jdegand',
6+
'DeveshChau',
7+
'stillst',
8+
'wandri',
9+
'webbomj',
10+
'kabrunko-dev',
11+
'Sanjar1304'
12+
];
13+
14+
module.exports = {
15+
contributors
16+
};

.github/github-action/index.js

+45-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,48 @@
1-
const core = require('@actions/core');
21
const github = require('@actions/github');
2+
const core = require('@actions/core');
3+
const contributors = require('./contributors');
4+
5+
async function run() {
6+
try {
7+
const title = github.context.payload.pull_request.title;
8+
const labels = [];
9+
10+
if(!title.startsWith('Answer:')) {
11+
return;
12+
}
13+
labels.push('answer');
14+
15+
const match = title.match(/Answer:\s*(\d+)/);
16+
if (match) {
17+
labels.push(parseInt(match[1], 10));
18+
}
319

4-
try {
5-
// `who-to-greet` input defined in action metadata file
6-
const nameToGreet = core.getInput('who-to-greet');
7-
console.log(`Hello ${nameToGreet}!`);
8-
const time = (new Date()).toTimeString();
9-
core.setOutput("time", time);
10-
// Get the JSON webhook payload for the event that triggered the workflow
11-
const payload = JSON.stringify(github.context.payload, undefined, 2)
12-
console.log(`The event payload: ${payload}`);
13-
} catch (error) {
14-
core.setFailed(error.message);
20+
const actor = github.context.actor;
21+
if(contributors.includes(actor)) {
22+
labels.push('to be reviewed');
23+
}
24+
25+
const githubToken = core.getInput('github_token');
26+
27+
const [owner, repo] = core.getInput('repo').split('/');
28+
const number =
29+
core.getInput('number') === ''
30+
? github.context.issue.number
31+
: parseInt(core.getInput('number'));
32+
33+
const octokit = github.getOctokit(githubToken);
34+
await octokit.rest.issues.addLabels({
35+
labels,
36+
owner,
37+
repo,
38+
issue_number: number
39+
});
40+
} catch (e) {
41+
if (e instanceof Error) {
42+
core.error(e);
43+
core.setFailed(e.message);
44+
}
45+
}
1546
}
47+
48+
run();

.github/workflows/label-issue.yml

+2-19
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,7 @@ jobs:
1414
- name: Install dependencies
1515
run: npm i @actions/core @actions/github
1616

17-
- name: add supporter labels
18-
uses: actions-ecosystem/action-add-labels@v1
19-
if: ${{ contains( fromJson('[ "tomalaforge", "alcaidio" , "svenson95", "jdegand", "DeveshChau", "stillst", "wandri", "webbomj", "kabrunko-dev", "Sanjar1304"]'), github.actor ) && startsWith(github.event.pull_request.title, 'Answer') }}
20-
with:
21-
github_token: ${{ secrets.github_token }}
22-
labels: supporter
23-
24-
- name: add answer labels
25-
uses: actions-ecosystem/action-add-labels@v1
26-
if: ${{ startsWith(github.event.pull_request.title, 'Answer') }}
27-
with:
28-
github_token: ${{ secrets.github_token }}
29-
labels: answer
30-
31-
- name: Hello world action step
17+
- name: Add labels
3218
uses: ./.github/github-action/
33-
id: hello
3419
with:
35-
who-to-greet: 'Mona the Octocat'
36-
- name: Get the output time
37-
run: echo "The time was ${{ steps.hello.outputs.time }}"
20+
github_token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)