90 lines
2.6 KiB
TypeScript
90 lines
2.6 KiB
TypeScript
import { Octokit } from "@octokit/core";
|
|
|
|
export const getOrgRepos = async (toolbox, token, org) => {
|
|
const { print } = toolbox;
|
|
const octokit = new Octokit({ auth: token });
|
|
try {
|
|
const response = await octokit.request("GET /orgs/{org}/repos", {
|
|
org: org,
|
|
per_page: 100,
|
|
});
|
|
if (response.status === 200) {
|
|
return response.data;
|
|
}
|
|
} catch (e) {
|
|
print.error('Not a valid organisation for your token access');
|
|
return null;
|
|
}
|
|
};
|
|
|
|
export const getOrgIssues = async (toolbox, token) => {
|
|
// const { print } = toolbox;
|
|
const repos = await getOrgRepos(toolbox, token, 'Photowall');
|
|
const repoNames = repos.map(item => item.name);
|
|
const allIssues = await Promise.all(repoNames.map(async (repoName) => {
|
|
const issues = await getOpenIssuesFromRepo(toolbox, token, repoName);
|
|
// console.log(`${repoName} - issues`, issues.length);
|
|
// return issues.map(item => `${item.number}-${item.title.substring(0, 10)}`);
|
|
return {repo: repoName, issues: issues};
|
|
}));
|
|
return allIssues.flat();
|
|
}
|
|
|
|
export const getOpenIssuesFromRepo = async (toolbox, token, repo) => {
|
|
const { print } = toolbox;
|
|
const octokit = new Octokit({ auth: token });
|
|
try {
|
|
const response = await octokit.request("GET /repos/{owner}/{repo}/issues", {
|
|
owner: "Photowall",
|
|
repo: repo,
|
|
per_page: 100,
|
|
});
|
|
if (response.status === 200) {
|
|
return response.data;
|
|
}
|
|
} catch (e) {
|
|
print.error('Not a valid issuenumber for this repository');
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export const getIssueFromRepo = async (toolbox, token, repo, issue_number) => {
|
|
const { print } = toolbox;
|
|
const octokit = new Octokit({ auth: token });
|
|
try {
|
|
const response = await octokit.request("GET /repos/{owner}/{repo}/issues/{issue_number}", {
|
|
owner: "Photowall",
|
|
repo: repo,
|
|
issue_number: issue_number,
|
|
});
|
|
if (response.status === 200) {
|
|
return response.data;
|
|
}
|
|
} catch (e) {
|
|
print.error('Not a valid issuenumber for this repository');
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export const createPullRequest = async (toolbox, token: string, repo: string, branch: string) => {
|
|
const { print } = toolbox;
|
|
const octokit = new Octokit({ auth: token });
|
|
try {
|
|
const response = await octokit.request('POST /repos/{owner}/{repo}/pulls', {
|
|
owner: 'Photowall',
|
|
repo: repo,
|
|
head: branch,
|
|
base: 'master'
|
|
});
|
|
console.log(`response`, response);
|
|
// if (response.status === 200) {
|
|
// return response.data;
|
|
// }
|
|
} catch (e) {
|
|
print.error('Not a valid branch');
|
|
return null;
|
|
}
|
|
|
|
|
|
}
|