-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Outputs a Slack-formatted message including open RFC issues in the Artsy GitHub org. **Example** ``` $ artsy scheduled:rfcs {"text":"There is one open RFC:","attachments":[{"fallback":"Open RFCs","color":"#36a64f","author_name":"jonallured","author_link":"https://github.com/jonallured","title":"RFC: Slight Rebranding for Artsy Engineering","title_link":"https://github.com/artsy/README/issues/364"}],"unfurl_links":false} ```
- Loading branch information
Showing
3 changed files
with
151 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,44 @@ | ||
import { Command } from "@oclif/command" | ||
import { GitHub } from "../../utils/github" | ||
|
||
export default class RFCs extends Command { | ||
static description = "lists open RFCs" | ||
|
||
async run() { | ||
require("dotenv").config() | ||
|
||
const github = new GitHub() | ||
const issues = await github.openRFCs() | ||
|
||
if (issues.length === 0) { | ||
const payload = JSON.stringify({ | ||
text: `No open RFCs this week.`, | ||
}) | ||
this.log(payload) | ||
return | ||
} | ||
|
||
const attachments = issues.map(issue => ({ | ||
fallback: "Open RFCs", | ||
color: "#36a64f", | ||
author_name: issue.author?.login, | ||
author_link: issue.author?.url, | ||
author_icon: issue.author?.avatarURL, | ||
title: issue.title, | ||
title_link: issue.url, | ||
})) | ||
|
||
const text = | ||
issues.length === 1 | ||
? `There is one open RFC:` | ||
: `There are ${issues.length} open RFCs:` | ||
|
||
const payload = JSON.stringify({ | ||
text, | ||
attachments, | ||
unfurl_links: false, | ||
}) | ||
|
||
this.log(payload) | ||
} | ||
} |
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,62 @@ | ||
import { graphql } from "@octokit/graphql" | ||
|
||
interface Issue { | ||
title: string | ||
url: string | ||
author: { | ||
url: string | ||
login: string | ||
avatarURL: string | ||
} | ||
} | ||
|
||
interface OpenRFCsGraphQLSearchResponse { | ||
edges: Array<{ node: Issue }> | ||
} | ||
|
||
export class GitHub { | ||
apiKey: string | ||
|
||
constructor() { | ||
if (!process.env.GITHUB_TOKEN) { | ||
throw new Error("GITHUB_TOKEN env var required") | ||
} | ||
|
||
this.apiKey = process.env.GITHUB_TOKEN | ||
} | ||
|
||
async openRFCs(): Promise<Issue[]> { | ||
const { search }: { search: OpenRFCsGraphQLSearchResponse } = await graphql( | ||
` | ||
{ | ||
search( | ||
query: "org:Artsy label:RFC state:open" | ||
type: ISSUE | ||
first: 100 | ||
) { | ||
edges { | ||
node { | ||
... on Issue { | ||
title | ||
url | ||
author { | ||
login | ||
url | ||
avatarUrl | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`, | ||
{ | ||
headers: { | ||
authorization: `token ${this.apiKey}`, | ||
}, | ||
} | ||
) | ||
|
||
return search.edges.map(edge => edge.node) | ||
} | ||
} |
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,45 @@ | ||
import { expect, test } from "@oclif/test" | ||
|
||
describe("scheduled:rfcs", () => { | ||
beforeEach(() => { | ||
process.env.GITHUB_TOKEN = "test" | ||
}) | ||
|
||
afterEach(() => { | ||
delete process.env.GITHUB_TOKEN | ||
}) | ||
|
||
test | ||
.nock("https://api.github.com", api => | ||
api.post("/graphql").reply(200, { | ||
data: { | ||
search: { | ||
edges: [ | ||
{ | ||
node: { | ||
title: "Test", | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}) | ||
) | ||
.stdout() | ||
.command(["scheduled:rfcs"]) | ||
.it("returns Slack-formatted open RFCs message", ctx => { | ||
expect(ctx.stdout.trim()).to.eq( | ||
JSON.stringify({ | ||
text: "There is one open RFC:", | ||
attachments: [ | ||
{ | ||
fallback: "Open RFCs", | ||
color: "#36a64f", | ||
title: "Test", | ||
}, | ||
], | ||
unfurl_links: false, | ||
}) | ||
) | ||
}) | ||
}) |