Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Example:
```yaml
addBinderLink: true
binderUrlSuffix: "?urlpath=lab-dev"
triageLabel: "status:Needs Triage"
```

## Deploying
Expand Down
5 changes: 5 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
"title": "Binder URL Suffix",
"description": "Suffix for Binder URL",
"type": "string"
},
"triageLabel": {
"title": "Triage label",
"description": "Triage label to apply on newly opened issues",
"type": "string"
}
},
"additionalProperties": false,
Expand Down
24 changes: 21 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

import Ajv, {JSONSchemaType} from 'ajv';
import Ajv, { JSONSchemaType } from 'ajv';

import * as fs from 'fs';

import { Context, Probot} from "probot";
import { Context, Probot } from "probot";


/**
Expand All @@ -20,6 +20,7 @@ interface RunData {
interface Config {
binderUrlSuffix?: string;
addBinderLink?: boolean;
triageLabel?: string;
}


Expand Down Expand Up @@ -48,6 +49,23 @@ async function getConfig(context: Context<any>): Promise<Config> {

export = (app: Probot) => {

/**
* Add triage label to opened issues
*/
app.on('issues.opened', async (context) => {
const { payload } = context;
const { issue } = payload;

const config = await getConfig(context);
const triageLabel = config['triageLabel'] ?? 'status:Needs Triage';

if (!(issue.labels ?? []).map((label) => label.name).includes(triageLabel)) {
await context.octokit.issues.addLabels(
context.issue({ labels: [triageLabel] })
);
}
});

app.on('pull_request.opened', async (context) => {
const head = context.payload.pull_request.head;
const ref = encodeURIComponent(head.ref);
Expand Down Expand Up @@ -106,7 +124,7 @@ To try out this branch on [binder](https://mybinder.org), follow this link: [![B
fs.writeFileSync("outputs.txt", "\n\n" + JSON.stringify(context.payload) + "\n", { flag: "a" });
}

const statuses = ["queued", "in_progress", "requested"];
const statuses = ["queued", "in_progress", "requested"];
await Promise.all(statuses.map(async (status) => {
const resp = await context.octokit.rest.actions.listWorkflowRuns({
owner,
Expand Down
34 changes: 34 additions & 0 deletions test/fixtures/issue_labelled.opened.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"action": "opened",
"issue": {
"number": 42,
"title": "Spelling error in the README file",
"user": {
"login": "hiimbex"
},
"labels": [
{
"id": 1362934389,
"node_id": "MDU6TGFiZWwxMzYyOTM0Mzg5",
"name": "status:Needs Triage",
"color": "d73a4a",
"default": true
}
],
"state": "open",
"locked": false,
"comments": 0,
"created_at": "2019-05-15T15:20:18Z",
"updated_at": "2019-05-15T15:20:18Z",
"closed_at": null,
"author_association": "OWNER",
"body": "It looks like you accidently spelled 'commit' with two 't's."
},
"changes": {},
"repository": {
"name": "testing-things",
"owner": {
"login": "hiimbex"
}
}
}
25 changes: 25 additions & 0 deletions test/fixtures/issue_no_label.opened.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"action": "opened",
"issue": {
"number": 42,
"title": "Spelling error in the README file",
"user": {
"login": "hiimbex"
},
"state": "open",
"locked": false,
"comments": 0,
"created_at": "2019-05-15T15:20:18Z",
"updated_at": "2019-05-15T15:20:18Z",
"closed_at": null,
"author_association": "OWNER",
"body": "It looks like you accidently spelled 'commit' with two 't's."
},
"changes": {},
"repository": {
"name": "testing-things",
"owner": {
"login": "hiimbex"
}
}
}
37 changes: 37 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Probot, ProbotOctokit } from "probot";
import duplicatePushes from './fixtures/duplicate_pushes.json';
import duplicatePRs from './fixtures/duplicate_pull_requests.json';
import openPREvent from './fixtures/pull_request.opened.json';
import openedIssueNoLabel from './fixtures/issue_no_label.opened.json';
import openedIssue from './fixtures/issue_labelled.opened.json';

const fs = require("fs");
const path = require("path");
Expand Down Expand Up @@ -33,6 +35,41 @@ describe("My Probot app", () => {
probot.load(myProbotApp);
});

test('add triage label to opened issue', async () => {

const config = {};
const configBuffer = Buffer.from(JSON.stringify(config));

const mock = nock("https://api.github.com")

.get("/repos/hiimbex/testing-things/contents/.github%2Fjupyterlab-probot.yml")
.reply(200, configBuffer.toString())

.post("/repos/hiimbex/testing-things/issues/42/labels")
.reply(200);

// Receive a webhook event
await probot.receive({ name: "issues", payload: openedIssueNoLabel });

expect(mock.pendingMocks()).toStrictEqual([]);
});

test('does not add triage label to opened issue that have it already', async () => {

const config = {};
const configBuffer = Buffer.from(JSON.stringify(config));

const mock = nock("https://api.github.com")

.get("/repos/hiimbex/testing-things/contents/.github%2Fjupyterlab-probot.yml")
.reply(200, configBuffer.toString());

// Receive a webhook event
await probot.receive({ name: "issues", payload: openedIssue });

expect(mock.pendingMocks()).toStrictEqual([]);
});

test('does not create a comment with a binder link', async () => {

const config = {};
Expand Down