-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.js
More file actions
35 lines (32 loc) · 860 Bytes
/
index.js
File metadata and controls
35 lines (32 loc) · 860 Bytes
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
const core = require('@actions/core');
const axios = require('axios');
async function run() {
try {
const name = core.getInput('name');
const org = core.getInput('org');
const accessToken = core.getInput('access-token');
const endpoint = org ? `/orgs/${org}/repos` : '/user/repos'
axios.post(
'https://api.github.com' + endpoint,
{
name,
private: false,
auto_init: true
},
{
headers: {
Authorization: 'token ' + accessToken
}
}
).then((repository) => {
core.info('Repository created: ' + repository.data.html_url);
core.setOutput('id', repository.data.node_id);
}).catch(() => {
core.info('Repository already exists.');
core.setOutput('id', null);
})
} catch (error) {
core.setFailed(error.message);
}
}
run();