-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
63 lines (57 loc) · 2.3 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const express = require('express')
const app = express()
const axios = require('axios');
const org_pat_map = require('./config.json')
const port = 3000
const env_list = process.env
for(var i in env_list) {
if(i.includes('PAT_')){
org_pat_map[i.replace('PAT_', '')] = env_list[i]
}
}
app.get('/repo/:github_repo_owner/:github_repo_name/registration-token', (req, res) => {
const registration_token_url= `https://api.github.com/repos/${req.params.github_repo_owner}/${req.params.github_repo_name}/actions/runners/registration-token`
const github_pat = org_pat_map[`${req.params.github_repo_owner}`]
const headers = {
'Authorization': `token ${github_pat}`
}
axios.post(registration_token_url,{},{headers: headers})
.then((github_res) => {
res.send(github_res['data']['token'])
})
})
app.get('/repo/:github_repo_owner/:github_repo_name/remove-token', (req, res) => {
const remove_token_url= `https://api.github.com/repos/${req.params.github_repo_owner}/${req.params.github_repo_name}/actions/runners/remove-token`
console.log(remove_token_url)
const github_pat = org_pat_map[`${req.params.github_repo_owner}`]
const headers = {
'Authorization': `token ${github_pat}`
}
axios.post(remove_token_url,{},{headers: headers})
.then((github_res) => {
res.send(github_res['data']['token'])
})
})
app.get('/:github_org_name/registration-token', (req, res) => {
const registration_token_url= `https://api.github.com/orgs/${req.params.github_org_name}/actions/runners/registration-token`
const github_pat = org_pat_map[`${req.params.github_org_name}`]
const headers = {
'Authorization': `token ${github_pat}`
}
axios.post(registration_token_url,{},{headers: headers})
.then((github_res) => {
res.send(github_res['data']['token'])
})
})
app.get('/:github_org_name/remove-token', (req, res) => {
const remove_token_url= `https://api.github.com/orgs/${req.params.github_org_name}/actions/runners/remove-token`
const github_pat = org_pat_map[`${req.params.github_org_name}`]
const headers = {
'Authorization': `token ${github_pat}`
}
axios.post(remove_token_url,{},{headers: headers})
.then((github_res) => {
res.send(github_res['data']['token'])
})
})
app.listen(3000);