Simplify code
This commit is contained in:
parent
a340f99141
commit
733794a7c3
|
@ -27,7 +27,7 @@ module.exports = robot => {
|
|||
async function checkOpenPullRequests (robot, context) {
|
||||
const { github, payload } = context
|
||||
const repo = payload.repository
|
||||
const repoInfo = { owner: payload.repository.owner.login, repo: payload.repository.name }
|
||||
const repoInfo = context.repo()
|
||||
const config = await getConfig(context, 'github-bot.yml', defaultConfig(robot, '.github/github-bot.yml'))
|
||||
const projectBoardConfig = config ? config['project-board'] : null
|
||||
|
||||
|
@ -68,14 +68,14 @@ async function checkOpenPullRequests (robot, context) {
|
|||
try {
|
||||
// Gather all open PRs in this repo
|
||||
const allPullRequests = await github.paginate(
|
||||
github.pullRequests.getAll({ ...repoInfo, per_page: 100 }),
|
||||
github.pullRequests.getAll(context.repo({ per_page: 100 })),
|
||||
res => res.data
|
||||
)
|
||||
|
||||
// And make sure they are assigned to the correct project column
|
||||
for (const pullRequest of allPullRequests) {
|
||||
try {
|
||||
await assignPullRequestToCorrectColumn(github, robot, repo, pullRequest, testedPullRequestLabelName, columns, config.slack.notification.room)
|
||||
await assignPullRequestToCorrectColumn(context, robot, repo, pullRequest, testedPullRequestLabelName, columns, config.slack.notification.room)
|
||||
} catch (err) {
|
||||
robot.log.error(`${botName} - Unhandled exception while processing PR: ${err}`, repoInfo)
|
||||
}
|
||||
|
@ -88,7 +88,8 @@ async function checkOpenPullRequests (robot, context) {
|
|||
}
|
||||
}
|
||||
|
||||
async function assignPullRequestToCorrectColumn (github, robot, repo, pullRequest, testedPullRequestLabelName, columns, room) {
|
||||
async function assignPullRequestToCorrectColumn (context, robot, repo, pullRequest, testedPullRequestLabelName, columns, room) {
|
||||
const { github } = context
|
||||
const prInfo = { owner: repo.owner.login, repo: repo.name, number: pullRequest.number }
|
||||
|
||||
let state = null
|
||||
|
|
|
@ -30,7 +30,7 @@ module.exports = (robot) => {
|
|||
async function assignPullRequestToReview (context, robot) {
|
||||
const { github, payload } = context
|
||||
const config = await getConfig(context, 'github-bot.yml', defaultConfig(robot, '.github/github-bot.yml'))
|
||||
const repoInfo = { owner: payload.repository.owner.login, repo: payload.repository.name }
|
||||
const repoInfo = context.repo()
|
||||
const prNumber = payload.pull_request.number
|
||||
|
||||
const projectBoardConfig = config ? config['project-board'] : null
|
||||
|
|
|
@ -37,7 +37,7 @@ module.exports = (robot) => {
|
|||
|
||||
async function assignIssueToBountyAwaitingForApproval (context, robot, assign) {
|
||||
const { github, payload } = context
|
||||
const repoInfo = { owner: payload.repository.owner.login, repo: payload.repository.name }
|
||||
const repoInfo = context.repo()
|
||||
const config = await getConfig(context, 'github-bot.yml', defaultConfig(robot, '.github/github-bot.yml'))
|
||||
const projectBoardConfig = config ? config['bounty-project-board'] : null
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ module.exports = (robot) => {
|
|||
|
||||
async function assignIssueToBountyBug (context, robot, assign) {
|
||||
const { github, payload } = context
|
||||
const repoInfo = { owner: payload.repository.owner.login, repo: payload.repository.name }
|
||||
const repoInfo = context.repo()
|
||||
const config = await getConfig(context, 'github-bot.yml', defaultConfig(robot, '.github/github-bot.yml'))
|
||||
const projectBoardConfig = config ? config['bounty-project-board'] : null
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ function registerForNewBounties (robot) {
|
|||
|
||||
async function notifyCollaborators (context, robot) {
|
||||
const { github, payload } = context
|
||||
const repoInfo = { owner: payload.repository.owner.login, repo: payload.repository.name }
|
||||
const repoInfo = context.repo()
|
||||
const config = await getConfig(context, 'github-bot.yml', defaultConfig(robot, '.github/github-bot.yml'))
|
||||
const bountyProjectBoardConfig = config ? config['bounty-project-board'] : null
|
||||
const gitHubTeamConfig = config ? config['github-team'] : null
|
||||
|
|
|
@ -43,8 +43,8 @@ function executeTemplate (templateString, templateVars) {
|
|||
async function greetNewContributor (context, robot) {
|
||||
const { github, payload } = context
|
||||
const config = await getConfig(context, 'github-bot.yml', defaultConfig(robot, '.github/github-bot.yml'))
|
||||
const repoInfo = { owner: payload.repository.owner.login, repo: payload.repository.name }
|
||||
const prInfo = { ...repoInfo, number: payload.pull_request.number }
|
||||
const repoInfo = context.repo()
|
||||
const prInfo = context.issue()
|
||||
|
||||
const welcomeBotConfig = config ? config['welcome-bot'] : null
|
||||
if (!welcomeBotConfig) {
|
||||
|
@ -68,10 +68,7 @@ async function greetNewContributor (context, robot) {
|
|||
if (process.env.DRY_RUN) {
|
||||
robot.log(`${botName} - Would have created comment in GHI`, prInfo, welcomeMessage)
|
||||
} else {
|
||||
await github.issues.createComment({
|
||||
...prInfo,
|
||||
body: welcomeMessage
|
||||
})
|
||||
await github.issues.createComment(context.issue({ body: welcomeMessage }))
|
||||
}
|
||||
|
||||
// Send message to Slack
|
||||
|
|
|
@ -42,7 +42,7 @@ async function processChangedProjectCard (robot, context) {
|
|||
return
|
||||
}
|
||||
|
||||
const repoInfo = { owner: repo.owner.login, repo: repo.name }
|
||||
const repoInfo = context.repo()
|
||||
const config = await getConfig(context, 'github-bot.yml', defaultConfig(robot, '.github/github-bot.yml'))
|
||||
const projectBoardConfig = config ? config['project-board'] : null
|
||||
const automatedTestsConfig = config ? config['automated-tests'] : null
|
||||
|
|
Loading…
Reference in New Issue