Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: assign collaborators #45

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 23 additions & 31 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ async function run() {
// A client to load data from GitHub
const client = new github.GitHub(token);

const addLabel: string[] = []
const removeLabelItems: string[] = []
const additions: string[] = []
const removals: string[] = []

if (enableVersionedRegex == 1) {
const regexVersion = versionedRegex.exec(issue_body)
Expand All @@ -48,7 +48,7 @@ async function run() {
}
else {
if (bodyMissingRegexLabel) {
removeLabelItems.push(bodyMissingRegexLabel);
removals.push(bodyMissingRegexLabel);
}
}
configPath = regexifyConfigPath(configPath, regexVersion[1])
Expand Down Expand Up @@ -82,18 +82,18 @@ async function run() {

for (const [label, globs] of labelRegexes.entries()) {
if (checkRegexes(issueContent, globs)) {
addLabel.push(label)
additions.push(label)
}
else {
removeLabelItems.push(label)
removals.push(label)
}
}
if (addLabel.length > 0) {
console.log(`Adding labels ${addLabel.toString()} to issue #${issue_number}`)
addLabels(client, issue_number, addLabel)
if (additions.length > 0) {
console.log(`Adding labels ${additions.toString()} to issue #${issue_number}`)
addLabels(client, issue_number, additions)
}

removeLabelItems.forEach(function (label, index) {
removals.forEach(function (label, _index) {
console.log(`Removing label ${label} from issue #${issue_number}`)
removeLabel(client, issue_number, label)
});
Expand Down Expand Up @@ -223,38 +223,23 @@ function checkRegexes(issue_body: string, regexes: string[]): boolean {
return true;
}

async function getLabels(
async function addLabels(
client: github.GitHub,
issue_number: number,
): Promise<string[]> {
const response = await client.issues.listLabelsOnIssue({
targets: string[]
) {
await client.issues.addLabels({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
issue_number: issue_number,
labels: targets
});
const data = response.data
if (response.status != 200) {
console.log('Unable to load labels. Exiting...')
process.exit(1);
}
const labels: string[] = [];
for (let i = 0; i < Object.keys(data).length; i++) {
labels.push(data[i].name)
}
return labels;
}

async function addLabels(
client: github.GitHub,
issue_number: number,
labels: string[]
) {

await client.issues.addLabels({
await client.issues.addAssignees({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
issue_number: issue_number,
labels: labels
assignees: targets
});
}

Expand All @@ -269,6 +254,13 @@ async function removeLabel(
issue_number: issue_number,
name: name
});

await client.issues.removeAssignees({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
issue_number: issue_number,
assignees: [name]
});
}

run();