Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to probot 10 #94

Merged
merged 5 commits into from
Oct 28, 2020
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
6 changes: 2 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,6 @@ module.exports = async (robot) => {
// To get your app running against GitHub, see:
// https://probot.github.io/docs/development/

return {
queue,
analytics,
}
robot.queue = queue
robot.analytics = analytics
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"lodash.merge": "^4.6.2",
"moment": "^2.27.0",
"ms": "^2.1.1",
"probot": "9.14.1",
"probot": "10.9.5",
"rexrex": "^1.3.0",
"smee-client": "^1.2.2",
"windsor-node": "^1.0.0"
Expand Down
11 changes: 5 additions & 6 deletions src/api.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
exports.closeIssue = function closeIssue(github, data) {
const { owner, repo, number, state = 'closed' } = data
const { owner, repo, issue_number, state = 'closed' } = data

return github.issues
.update({
owner,
repo,
issue_number: number,
issue_number,
state,
mediaType: {
previews: ['symmetra'],
Expand All @@ -19,13 +19,13 @@ exports.closeIssue = function closeIssue(github, data) {
}

exports.getPullRequest = function getPullRequest(github, data) {
const { owner, repo, number } = data
const { owner, repo, pull_number } = data

return github.pulls
.get({
owner,
repo,
pull_number: number,
pull_number,
mediaType: {
previews: ['symmetra', 'shadow-cat'],
},
Expand All @@ -52,11 +52,10 @@ exports.createLabel = function createLabel(github, data) {
})
}

exports.addLabels = function addLabels(github, { labels, number, ...data }) {
exports.addLabels = function addLabels(github, { labels, ...data }) {
return github.issues
.addLabels({
...data,
issue_number: number,
labels: many(labels),
mediaType: {
previews: ['symmetra'],
Expand Down
22 changes: 1 addition & 21 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const ms = require('ms')
const { Context } = require('probot')
const merge = require('lodash.merge')
const Sentry = require('@sentry/node')

const { CLOSE, MERGE } = require('./constants')
Expand Down Expand Up @@ -32,27 +30,9 @@ exports.CONFIG_FILE = CONFIG_FILE

// const mergeOptions = { arrayMerge: (destinationArray, sourceArray /* options */) => sourceArray }

function createEvent(context, owner, repo) {
const newContext = merge({}, context)
newContext.payload.repository.owner.login = owner
newContext.payload.repository.owner.name = owner
newContext.payload.repository.name = repo
return newContext
}

module.exports = async (context) => {
try {
let config = await context.config(CONFIG_FILE, defaultConfig /* mergeOptions */)

// TODO remove config.extends and relace with _extends
if (typeof config.extends === 'string' && config.extends.indexOf('/') > -1) {
const [owner, repo] = config.extends.trim().split('/')
const globalContext = new Context(createEvent(context, owner, repo), context.github)
const globalConfig = globalContext.config(CONFIG_FILE, defaultConfig)
config = merge(globalConfig, config)
}

return config
return await context.config(CONFIG_FILE, defaultConfig /* mergeOptions */)
} catch (err) {
const repo = context.repo()

Expand Down
9 changes: 7 additions & 2 deletions src/issue/labeled.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = (queue) => async (context) => {
.replace('$DELAY', time == null ? '' : ms(time, { long: true }))
.replace('$LABEL', label.name)
.replace('$AUTHOR', thread.user.login)
context.github.issues.createComment(context.repo({ body, issue_number: thread.number }))
context.github.issues.createComment(context.issue({ body }))
}
}

Expand Down Expand Up @@ -68,5 +68,10 @@ module.exports = (queue) => async (context) => {

module.exports.process = (robot) => async ({ data /* id */ }) => {
const github = await robot.auth(data.installation_id)
return await closeIssue(github, data)
return await closeIssue(github, {
...data,
number: undefined,
// TODO change this to just use number
issue_number: data.issue_number || data.number,
})
}
14 changes: 9 additions & 5 deletions src/pull/labeled.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module.exports = (queue) => async (context) => {
return (
queue
.createJob({
...context.issue({ installation_id: context.payload.installation.id }),
...context.pullRequest({ installation_id: context.payload.installation.id }),
action: MERGE,
method,
})
Expand Down Expand Up @@ -78,14 +78,18 @@ module.exports = (queue) => async (context) => {
}

module.exports.process = (robot) => async ({
data: { installation_id, owner, repo, number, method = 'merge' },
data: { installation_id, owner, repo, number, pull_number, method = 'merge' },
}) => {
let github
let pull

// TODO change this to just use number
const the_number = pull_number || number

try {
github = await robot.auth(installation_id)

pull = await getPullRequest(github, { owner, repo, number })
pull = await getPullRequest(github, { owner, repo, pull_number: the_number })
} catch (error) {
const Sentry = require('@sentry/node')
Sentry.configureScope((scope) => {
Expand Down Expand Up @@ -159,7 +163,7 @@ module.exports.process = (robot) => async ({
github.pulls.merge({
owner,
repo,
pull_number: number,
pull_number: the_number,
sha,
merge_method: methods[(initialIndex + i) % methods.length],
})
Expand Down Expand Up @@ -191,7 +195,7 @@ module.exports.process = (robot) => async ({
return await github.pulls.updateBranch({
owner,
repo,
pull_number: number,
pull_number: the_number,
expected_head_sha: pull.head.sha,
headers: {
accept: 'application/vnd.github.lydian-preview+json',
Expand Down
10 changes: 7 additions & 3 deletions src/thread/labeled.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ module.exports = (queue) => async (context) => {

await queue
.createJob(
context.repo({
context.issue({
installation_id: context.payload.installation.id,
action: COMMENT,
body,
issue_number: thread.number,
})
)
.setId(jobId)
Expand All @@ -74,5 +73,10 @@ module.exports = (queue) => async (context) => {

module.exports.process = (robot) => async ({ data /* id */ }) => {
const github = await robot.auth(data.installation_id)
return await github.issues.createComment(data)
return await github.issues.createComment({
...data,
number: undefined,
// TODO change this to just use number
issue_number: data.issue_number || data.number,
})
}
4 changes: 2 additions & 2 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const r = require('rexrex')

// We might need different ids for different jobs in the future but this works for now
module.exports.getId = function getId(context, options) {
const { owner, repo, number, action } = context.issue(options)
return `${owner}:${repo}:${number}${action ? `:${action}` : ''}`
const { owner, repo, issue_number, action } = context.issue(options)
return `${owner}:${repo}:${issue_number}${action ? `:${action}` : ''}`
}

module.exports.executeAction = function executeAction(action, map) {
Expand Down
2 changes: 1 addition & 1 deletion src/verify-payment-plan.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ module.exports = async function verifyPaymentPlan(robot, context) {
}

function getAssociatedAccount(github, account_id) {
return github.apps.checkAccountIsAssociatedWithAny({ account_id })
return github.apps.getSubscriptionPlanForAccount({ account_id })
}

const privateReposAllowedPattern = r.and(
Expand Down
Loading