Skip to content

Commit

Permalink
use a regular issue comment instead of a PR review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahs committed May 17, 2021
1 parent 1001502 commit 42baac1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
29 changes: 13 additions & 16 deletions script/content-migrations/comment-on-open-prs.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env node

const { listPulls, createReviewComment } = require('../helpers/git-utils')
const { listPulls, createIssueComment } = require('../helpers/git-utils')

// [start-readme]
//
// This script finds all open PRs from active branches that touch content files, and adds a comment
// with a prompt to enter a slash command and update files. The idea is to help writers and other Hubbers
// update their open branches and mitigate conflicts with the main branch.
// with steps to run some commands. The idea is to help writers and other Hubbers update their
// open branches and mitigate conflicts with the main branch.
//
// [end-readme]

Expand All @@ -22,21 +22,18 @@ const options = {
}

const comment = `
Hello! The docs-engineering team has just published an update that touches all content files in the repo. To reduce conflicts with \`main\`, we wanted to offer a programmatic option to update your branch.
👋 Hello! The docs-engineering team has just published an update that touches all content files in the repo. To reduce conflicts with \`main\`, we are sending out this message to help folks update their branches.
To take advantage of this option, in a new comment on this PR, type and enter: \`/update-content-in-branch\`.
You'll need to do the following steps in Terminal. If you're not into that, ask in #docs-engineering and we'll help out!
This is a custom slash command that will trigger a GitHub Action workflow to do the following:
1. Check out the branch associated with this PR. Don't update from \`main\` yet.
2. Run: \`script/content-migrations/remove-map-topics.js && script/content-migrations/update-tocs.js\`
3. Commit: \`git add . && git commit -m 'ran content migration scripts'\`
4. Update: \`git pull origin main\`
1. Check out your branch.
2. Run some special scripts.
3. Commit and push the results back to your branch.
You may still have some conflicts to resolve. Feel free to ask us if you have questions or need help!
Once that's done, you can update from \`main\`. You may still have some conflicts to resolve.
Feel free to ask if you have questions or need help!
For a 5min demo of what the scripts do and why they're needed, check out https://www.loom.com/share/fa6501580b2a44d7a8a4357ee51e0c99.
For a 5min demo of what the scripts do and why they're needed, check out [this screencast](https://www.loom.com/share/fa6501580b2a44d7a8a4357ee51e0c99).
`

main()
Expand All @@ -51,7 +48,7 @@ async function main () {

// for every open PR, create a review comment
await Promise.all(openPullNumbers.map(async (pullNumber) => {
await createReviewComment(options.owner, options.repo, pullNumber, comment)
console.log(`added a comment to PR #${pullNumber}`)
await createIssueComment(options.owner, options.repo, pullNumber, comment)
console.log(`Added a comment to PR #${pullNumber}`)
}))
}
8 changes: 4 additions & 4 deletions script/helpers/git-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ async function listPulls (owner, repo) {
}
}

async function createReviewComment (owner, repo, pullNumber, body) {
async function createIssueComment (owner, repo, pullNumber, body) {
try {
const { data } = await github.pulls.createReviewComment({
const { data } = await github.issues.createComment({
owner,
repo,
pull_number: pullNumber,
issue_number: pullNumber,
body
})
return data
Expand All @@ -133,5 +133,5 @@ module.exports = {
getContents,
listMatchingRefs,
listPulls,
createReviewComment
createIssueComment
}
4 changes: 3 additions & 1 deletion script/helpers/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ if (!process.env.GITHUB_TOKEN) {
// 3. an installation token granted via GitHub Actions
const apiToken = process.env.GITHUB_TOKEN

const { Octokit } = require('@octokit/rest')

// See https://github.com/octokit/rest.js/issues/1207
module.exports = function github () {
return require('@octokit/rest')({
return new Octokit({
auth: `token ${apiToken}`
})
}

0 comments on commit 42baac1

Please sign in to comment.