|
| 1 | +const express = require('express') |
| 2 | +const app = express() |
| 3 | +const axios = require('axios'); |
| 4 | +const org_pat_map = require('./config.json') |
| 5 | +const port = 3000 |
| 6 | + |
| 7 | +app.get('/repo/:github_repo_owner/:github_repo_name/registration-token', (req, res) => { |
| 8 | + const registration_token_url= `https://api.github.com/repos/${req.params.github_repo_owner}/${req.params.github_repo_name}/actions/runners/registration-token` |
| 9 | + const github_pat = org_pat_map[`${req.params.github_repo_owner}`] |
| 10 | + const headers = { |
| 11 | + 'Authorization': `token ${github_pat}` |
| 12 | + } |
| 13 | + axios.post(registration_token_url,{},{headers: headers}) |
| 14 | + .then((github_res) => { |
| 15 | + res.send(github_res['data']['token']) |
| 16 | + }) |
| 17 | +}) |
| 18 | + |
| 19 | +app.get('/repo/:github_repo_owner/:github_repo_name/remove-token', (req, res) => { |
| 20 | + const remove_token_url= `https://api.github.com/repos/${req.params.github_repo_owner}/${req.params.github_repo_name}/actions/runners/remove-token` |
| 21 | + console.log(remove_token_url) |
| 22 | + const github_pat = org_pat_map[`${req.params.github_repo_owner}`] |
| 23 | + const headers = { |
| 24 | + 'Authorization': `token ${github_pat}` |
| 25 | + } |
| 26 | + axios.post(remove_token_url,{},{headers: headers}) |
| 27 | + .then((github_res) => { |
| 28 | + res.send(github_res['data']['token']) |
| 29 | + }) |
| 30 | +}) |
| 31 | + |
| 32 | +app.get('/:github_org_name/registration-token', (req, res) => { |
| 33 | + const registration_token_url= `https://api.github.com/orgs/${req.params.github_org_name}/actions/runners/registration-token` |
| 34 | + const github_pat = org_pat_map[`${req.params.github_org_name}`] |
| 35 | + const headers = { |
| 36 | + 'Authorization': `token ${github_pat}` |
| 37 | + } |
| 38 | + axios.post(registration_token_url,{},{headers: headers}) |
| 39 | + .then((github_res) => { |
| 40 | + res.send(github_res['data']['token']) |
| 41 | + }) |
| 42 | +}) |
| 43 | + |
| 44 | +app.get('/:github_org_name/remove-token', (req, res) => { |
| 45 | + const remove_token_url= `https://api.github.com/orgs/${req.params.github_org_name}/actions/runners/remove-token` |
| 46 | + const github_pat = org_pat_map[`${req.params.github_org_name}`] |
| 47 | + const headers = { |
| 48 | + 'Authorization': `token ${github_pat}` |
| 49 | + } |
| 50 | + axios.post(remove_token_url,{},{headers: headers}) |
| 51 | + .then((github_res) => { |
| 52 | + res.send(github_res['data']['token']) |
| 53 | + }) |
| 54 | +}) |
| 55 | + |
| 56 | +app.listen(3000); |
0 commit comments