-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
49 lines (37 loc) · 1.54 KB
/
index.js
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
import core from '@actions/core';
import github from '@actions/github';
import { Octokit } from '@octokit/core'; // eslint-disable-line import/no-extraneous-dependencies
import { paginateGraphQL } from '@octokit/plugin-paginate-graphql';
import { ApiWrapper } from './apiwrapper.js'; // eslint-disable-line import/extensions
import { RepositoryProjectsManager } from './projects.js'; // eslint-disable-line import/extensions
const GraphQlOctokit = Octokit.plugin(paginateGraphQL);
// https://github.com/octokit/authentication-strategies.js
// example: https://github.com/octokit/graphql.js/issues/61#issuecomment-542399763
// for token type installation, pass only the token
const octokit = new GraphQlOctokit({ auth: process.env.GITHUB_TOKEN });
const hasDuplicates = (array) => new Set(array).size !== array.length;
try {
const projectTitlesInput = core.getInput('project-titles');
const titles = projectTitlesInput.split(/\s+/);
if (hasDuplicates(titles)) {
throw new Error(`Duplicate project titles are not allowed: ${titles}`);
}
// Get the JSON webhook payload for the event that triggered the workflow
const {
context: {
payload: {
repository,
},
},
} = github;
const apiWrapper = new ApiWrapper({ octokit });
const rpm = new RepositoryProjectsManager({
ownerName: repository.owner.login,
repositoryName: repository.name,
apiWrapper,
});
await rpm.sync(titles);
core.setOutput('project-titles', rpm.projects().map((p) => p.title).join(' '));
} catch (error) {
core.setFailed(error.message);
}