Skip to content

Commit

Permalink
feat: added assignees support
Browse files Browse the repository at this point in the history
  • Loading branch information
arctic-hen7 committed Jan 11, 2022
1 parent 65bca18 commit abc63bc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 20 deletions.
32 changes: 22 additions & 10 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90793,13 +90793,14 @@ const newIssueHandler = async (ctx) => {
// Get the body of the issue so that we can parse it
const { data } = await ctx.octokit.issues.get(params);
// Get the labels out of that
let labels = getRequestedLabels(data.body);
let { labels, assignees } = getData(data.body);
// If we didn't find the appropriate formatting, we'll get `undefined`, in which case this issue wasn't created with Tribble and we should shut up
if (labels === undefined) {
if (labels === undefined || assignees == undefined) {
return;
}
// Add the labels to that issue
// Add the labels and assignees to that issue
await ctx.octokit.issues.addLabels({ labels, ...params });
await ctx.octokit.issues.addAssignees({ assignees, ...params });
} catch(err) {
console.error(err);
// We have an error, but we have the details of the issue, so comment on it
Expand All @@ -90809,7 +90810,7 @@ const newIssueHandler = async (ctx) => {
};

// If Tribble's data format ever changes, we need to update this
const getRequestedLabels = (issueBody) => {
const getData = (issueBody) => {
// The relevant `<details>` block in a Tribble-formatted issue will always come at the end
// We add to this because we need to get the actual contained text
const detailsOpenIdx = issueBody.lastIndexOf("</summary>") + 10;
Expand All @@ -90820,15 +90821,26 @@ const getRequestedLabels = (issueBody) => {
}
const encoded = issueBody.substring(detailsOpenIdx, detailsCloseIdx).trim();
// Now decode that
let labelsString = Buffer.from(encoded, "base64").toString("utf-8");
const labelsString = Buffer.from(encoded, "base64").toString("utf-8");
// We now have a list of tags delimited by ','
let labels = labelsString.split(",");
// GitHub has a very specific format it wants
let githubLabels = labels.map(name => {
return { name };
});

return labels;
// Check any of the labels for beign assignees (they'd start with an `@`)
let assignees = [];
for (let i in labels) {
let label = labels[i];
if (label[0] == "@") {
assignees.push(label);
delete labels[i];
} else if (label[0] == "\\" && label[1] == "@") {
// The user has escaped an assignee, so remove the `\`
labels[i] = label.substr(1);
}
}
// We may have removed from elements from the labels, so clear out the empty ones
labels = labels.filter(label => label !== undefined);

return { labels, assignees };
};


Expand Down
32 changes: 22 additions & 10 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ const newIssueHandler = async (ctx) => {
// Get the body of the issue so that we can parse it
const { data } = await ctx.octokit.issues.get(params);
// Get the labels out of that
let labels = getRequestedLabels(data.body);
let { labels, assignees } = getData(data.body);
// If we didn't find the appropriate formatting, we'll get `undefined`, in which case this issue wasn't created with Tribble and we should shut up
if (labels === undefined) {
if (labels === undefined || assignees == undefined) {
return;
}
// Add the labels to that issue
// Add the labels and assignees to that issue
await ctx.octokit.issues.addLabels({ labels, ...params });
await ctx.octokit.issues.addAssignees({ assignees, ...params });
} catch(err) {
console.error(err);
// We have an error, but we have the details of the issue, so comment on it
Expand All @@ -26,7 +27,7 @@ const newIssueHandler = async (ctx) => {
};

// If Tribble's data format ever changes, we need to update this
const getRequestedLabels = (issueBody) => {
const getData = (issueBody) => {
// The relevant `<details>` block in a Tribble-formatted issue will always come at the end
// We add to this because we need to get the actual contained text
const detailsOpenIdx = issueBody.lastIndexOf("</summary>") + 10;
Expand All @@ -37,13 +38,24 @@ const getRequestedLabels = (issueBody) => {
}
const encoded = issueBody.substring(detailsOpenIdx, detailsCloseIdx).trim();
// Now decode that
let labelsString = Buffer.from(encoded, "base64").toString("utf-8");
const labelsString = Buffer.from(encoded, "base64").toString("utf-8");
// We now have a list of tags delimited by ','
let labels = labelsString.split(",");
// GitHub has a very specific format it wants
let githubLabels = labels.map(name => {
return { name };
});

return labels;
// Check any of the labels for beign assignees (they'd start with an `@`)
let assignees = [];
for (let i in labels) {
let label = labels[i];
if (label[0] == "@") {
assignees.push(label);
delete labels[i];
} else if (label[0] == "\\" && label[1] == "@") {
// The user has escaped an assignee, so remove the `\`
labels[i] = label.substr(1);
}
}
// We may have removed from elements from the labels, so clear out the empty ones
labels = labels.filter(label => label !== undefined);

return { labels, assignees };
};

0 comments on commit abc63bc

Please sign in to comment.