1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tslib_1 = require("tslib");
|
4 | const Github = require("@octokit/rest");
|
5 | const octokit = new Github({
|
6 | headers: {
|
7 | accept: 'application/vnd.github.symmetra-preview+json',
|
8 | },
|
9 | });
|
10 | function authenticate(params) {
|
11 | const { authToken, } = params;
|
12 | return new Promise((resolve, reject) => {
|
13 | if (!authToken) {
|
14 | return reject(new Error('Auth token is required.'));
|
15 | }
|
16 | octokit.authenticate({
|
17 | type: 'token',
|
18 | token: authToken,
|
19 | });
|
20 | return resolve();
|
21 | });
|
22 | }
|
23 | function getAuthenticatedOctokit(params) {
|
24 | return authenticate(params)
|
25 | .then(() => {
|
26 | return octokit;
|
27 | });
|
28 | }
|
29 | exports.getAuthenticatedOctokit = getAuthenticatedOctokit;
|
30 | function getReposRaw(params) {
|
31 | const { repoQuery, } = params;
|
32 | return authenticate(params)
|
33 | .then(async () => {
|
34 | let response = await octokit.search.repos({
|
35 | q: repoQuery,
|
36 | per_page: 50,
|
37 | });
|
38 | let items = response.data.items;
|
39 |
|
40 | while (octokit.hasNextPage(response)) {
|
41 |
|
42 | response = await octokit.getNextPage(response);
|
43 | items = items.concat(response.data.items);
|
44 | }
|
45 | return items;
|
46 | });
|
47 | }
|
48 | exports.getReposRaw = getReposRaw;
|
49 | function getRepos(options) {
|
50 | const { filter: repoFilterString, } = options;
|
51 | const lmsRepoRE = new RegExp(repoFilterString);
|
52 | return getReposRaw(options)
|
53 | .then((repos_raw) => {
|
54 | return repos_raw.map(repo => {
|
55 | return {
|
56 | name: repo.name,
|
57 | owner: repo.owner.login,
|
58 | repo: repo.name,
|
59 | full_name: repo.full_name,
|
60 | ssh_url: repo.ssh_url,
|
61 | git_url: repo.git_url,
|
62 | clone_url: repo.clone_url,
|
63 | };
|
64 | })
|
65 | .filter((repo) => {
|
66 | return lmsRepoRE.test(repo.name);
|
67 | });
|
68 | });
|
69 | }
|
70 | exports.getRepos = getRepos;
|
71 | function editRepo(params) {
|
72 | const {
|
73 |
|
74 | authToken } = params, passedParams = tslib_1.__rest(params, ["authToken"]);
|
75 | return authenticate(params)
|
76 | .then(() => {
|
77 | return octokit.repos.edit(passedParams);
|
78 | });
|
79 | }
|
80 | exports.editRepo = editRepo;
|
81 | function addRepoToTeam(params) {
|
82 | const {
|
83 |
|
84 | authToken } = params, passedParams = tslib_1.__rest(params, ["authToken"]);
|
85 | return authenticate(params)
|
86 | .then(async () => {
|
87 |
|
88 | return octokit.orgs.addTeamRepo(passedParams);
|
89 | });
|
90 | }
|
91 | exports.addRepoToTeam = addRepoToTeam;
|
92 | function getTeams(params) {
|
93 | const {
|
94 |
|
95 | authToken } = params, passedParams = tslib_1.__rest(params, ["authToken"]);
|
96 | const serviceParams = Object.assign({ org: 'RoundtableLearning' }, passedParams);
|
97 | return authenticate(params)
|
98 | .then(async () => {
|
99 |
|
100 | return octokit.orgs.getTeams(serviceParams);
|
101 | })
|
102 | .then(response => response.data);
|
103 | }
|
104 | exports.getTeams = getTeams;
|