@yuki-no/plugin-sdk
Version:
A GitHub Action that tracks changes between repositories. It creates GitHub issues based on commits from a head repository, making it ideal for documentation translation projects.
46 lines (45 loc) • 1.83 kB
JavaScript
import { isNotEmpty } from '../utils/common';
import { extractHashFromIssue } from '../utils/common';
import { log } from '../utils/log';
export const getOpenedIssues = async (github) => {
log('I', 'getOpenedIssues :: Starting search for open issues');
const issues = [];
let page = 1;
let totalIssuesChecked = 0;
while (true) {
const { data } = await github.api.issues.listForRepo({
...github.ownerAndRepo,
state: 'open',
per_page: 100,
page,
});
if (data.length === 0) {
break;
}
totalIssuesChecked += data.length;
const openedIssuesWithoutHash = data.map(item => ({
number: item.number,
body: item.body ?? '',
isoDate: item.created_at,
labels: item.labels
.map(convGithubIssueLabelToString)
.filter(isNotEmpty)
.sort(),
}));
const openedYukiNoIssues = openedIssuesWithoutHash
.filter(issue => isYukiNoIssue(github.configuredLabels, issue))
.map(issue => ({ ...issue, hash: extractHashFromIssue(issue) }))
.filter(hasHash);
issues.push(...openedYukiNoIssues);
page++;
if (data.length < 100) {
break;
}
}
log('I', `getOpenedIssues :: Completed: Found ${issues.length} Yuki-no issues out of ${totalIssuesChecked} total issues`);
issues.sort((a, b) => (a.isoDate > b.isoDate ? 1 : -1));
return issues;
};
const convGithubIssueLabelToString = (label) => (typeof label === 'string' ? label : (label.name ?? ''));
const isYukiNoIssue = (configuredLabels, issue) => configuredLabels.every(cl => issue.labels.includes(cl));
const hasHash = (issue) => issue.hash !== undefined && issue.hash.length > 0;