Skip to content

Commit

Permalink
feat: update RFCs reminder
Browse files Browse the repository at this point in the history
- Use Slack Block Kit UI
- Include pull requests with `RFC` label
- Include additional context
  • Loading branch information
dblandin committed Feb 12, 2021
1 parent b9a4911 commit 6529e15
Show file tree
Hide file tree
Showing 8 changed files with 333 additions and 114 deletions.
2 changes: 1 addition & 1 deletion src/__generated__/github-schema-loader.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

162 changes: 129 additions & 33 deletions src/__generated__/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

110 changes: 87 additions & 23 deletions src/commands/scheduled/rfcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,110 @@ import { githubClient } from "../../utils/github"
export default class RFCs extends Command {
static description = "lists open RFCs"

static SearchURL =
"https://github.com/search?q=org:Artsy+label:RFC+state:open"

async run() {
require("dotenv").config()

const { data: { search }} = await githubClient().query<OpenRequestsForCommentsQuery>({
const {
data: { search },
} = await githubClient().query<OpenRequestsForCommentsQuery>({
query: OpenRequestsForComments,
});
})

const blocks = []

if (search.issueCount === 0) {
const payload = JSON.stringify({
text: `No open RFCs this week.`,
blocks.push({
type: "section",
text: {
type: "plain_text",
text: "No open RFCs this week",
},
})
this.log(payload)
this.log(JSON.stringify({ blocks }))
return
} else {
let text: string
if (search.issueCount === 1) {
text = `There is <${RFCs.SearchURL}|*1 open RFC*>:`
} else {
text = `There are <${RFCs.SearchURL}|*${search.issueCount} open RFCs*>:`
}
blocks.push({
type: "section",
text: {
type: "mrkdwn",
text,
},
})
}

const attachments = search.nodes?.map(issue => {
if (issue?.__typename === "Issue" || issue?.__typename === "PullRequest") {
return {
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,
search.nodes?.forEach((issue, index) => {
if (
issue?.__typename === "Issue" ||
issue?.__typename === "PullRequest"
) {
let issueText = `<${issue.url}|${issue.title}>`

if (issue.timelineItems.nodes?.length) {
const comment = issue.timelineItems.nodes[0]
if (comment?.__typename === "IssueComment") {
issueText += `\n\n:speech_balloon: _Last comment on <!date^${this.convertTimestampToEpoch(
comment.createdAt
)}^{date_short_pretty}^${comment.url}|${comment.createdAt}> by <${
issue.author?.url
}|${issue.author?.login}>_`
}
}

blocks.push(
...[
{
type: "section",
text: {
type: "mrkdwn",
text: issueText,
},
},
{
type: "context",
elements: [
{
type: "image",
image_url: issue.author?.avatarUrl,
alt_text: issue.author?.login,
},
{
type: "mrkdwn",
text: `Created by <${issue.author?.url}|${
issue.author?.login
}> on <!date^${this.convertTimestampToEpoch(
issue.createdAt
)}^{date_short_pretty}|${issue.createdAt}> / ${
issue.participants.totalCount
} participants`,
},
],
},
]
)

if (index < search.issueCount - 1) {
blocks.push({ type: "divider" })
}
}
})

const text =
search.issueCount === 1
? `There is one open RFC:`
: `There are ${search.issueCount} open RFCs:`

const payload = JSON.stringify({
text,
attachments,
unfurl_links: false,
blocks,
})

this.log(payload)
}

convertTimestampToEpoch(timestamp: string) {
return +Date.parse(timestamp) / 1000
}
}
35 changes: 20 additions & 15 deletions src/generate-types.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const fetch = require('cross-fetch');
const fs = require('fs');
const fetch = require("cross-fetch")
const fs = require("fs")

fetch(`https://api.github.com/graphql`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
variables: {},
query: `
Expand All @@ -21,24 +21,29 @@ fetch(`https://api.github.com/graphql`, {
`,
}),
headers: {
authorization: `token d8aead0d846a16777eb47b751c0bc975be33814b`
authorization: `token d8aead0d846a16777eb47b751c0bc975be33814b`,
},
}).then(result => { console.log(result.json()); return result.json()})
})
.then(result => {
const possibleTypes = {};
console.log(result.json())
return result.json()
})
.then(result => {
const possibleTypes = {}

result.data.__schema.types.forEach(supertype => {
if (supertype.possibleTypes) {
possibleTypes[supertype.name] =
supertype.possibleTypes.map(subtype => subtype.name);
possibleTypes[supertype.name] = supertype.possibleTypes.map(
subtype => subtype.name
)
}
});
})

fs.writeFile('./possibleTypes.json', JSON.stringify(possibleTypes), err => {
fs.writeFile("./possibleTypes.json", JSON.stringify(possibleTypes), err => {
if (err) {
console.error('Error writing possibleTypes.json', err);
console.error("Error writing possibleTypes.json", err)
} else {
console.log('Fragment types successfully extracted!');
console.log("Fragment types successfully extracted!")
}
});
});
})
})
Loading

0 comments on commit 6529e15

Please sign in to comment.