-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
575975b
commit e1d3046
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module.exports = (app) => { | ||
// We'll act on any newly opened issues | ||
app.on("issues.opened", newIssueHandler); | ||
}; | ||
|
||
const newIssueHandler = async (ctx) => { | ||
// Get the parameters for this issue so that we can add labels to it and comment on it | ||
const params = ctx.issue(); | ||
try { | ||
// Get the body of the issue so that we can parse it | ||
const { body } = await ctx.octokit.issues.get(issueParams); | ||
// Get the labels out of that | ||
let labels = getRequestedLabels(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) { | ||
return; | ||
} | ||
// Add the labels to that issue | ||
await ctx.octokit.issues.addLabels({ labels, ...params }); | ||
} catch(err) { | ||
// We have an error, but we have the details of the issue, so comment on it | ||
let errBody = "This repo is set up to triage issues with [Tribble](https://github.com/arctic-hen7/tribble), but this issue couldn't be processed. If you deliberately didn't use Tribble to report this issue, you can safely ignore this warning. If you did, something's gone wrong here."; | ||
await ctx.octokit.issues.createComment({ body: errBody, ...params }); | ||
} | ||
}; | ||
|
||
// If Tribble's data format ever changes, we need to update this | ||
const getRequestedLabels = (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("<details>\n<summary>Tribble internal data</summary>") + 51; | ||
const detailsCloseIdx = issueBody.lastIndexOf("</details>"); | ||
// The indexing will return `-1` if it found nothing (but one had 51 added) | ||
if (detailsOpenIdx === 50 || detailsCloseIdx === -1) { | ||
return undefined; | ||
} | ||
const encoded = issueBody.substring(detailsOpenIdx, detailsCloseIdx).trim(); | ||
// Now decode that | ||
let 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 githubLabels; | ||
}; | ||
|
||
const test = `This report is reporting a bug. Description: test. Boolean: true | ||
<details> | ||
<summary>Tribble internal data</summary> | ||
QzpidWcsQTpmcm9udGVuZA== | ||
</details>`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const { run } = require('@probot/adapter-github-actions') | ||
const app = require("./app"); | ||
|
||
run(app).catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |