Skip to content

Commit

Permalink
fix: An error is reported when selecting a single pr update (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
baiwusanyu-c authored Mar 24, 2023
1 parent 0236995 commit 773b5fb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
26 changes: 14 additions & 12 deletions packages/core/runtime.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import prompts from 'prompts'
import ora from 'ora'
import { log } from '@pr-checker/utils'
import { isEmptyObj, log } from '@pr-checker/utils'
import { Table } from 'console-table-printer'
import chalk from 'chalk'
import { createPrOption, createRepoOption, typeOption } from './command-option'
Expand Down Expand Up @@ -88,7 +88,7 @@ async function updatePR(prl: IPRListItem[],
prSelectRes: IPRSelect,
githubApi: GitApi) {
const updateRes = await Promise.all(createRunList(prl.length, async(i: number) => {
if (prSelectRes.prSelect[i].isNeedUpdate) {
if (prSelectRes.prSelect[i] && prSelectRes.prSelect[i].isNeedUpdate) {
await githubApi.updatePR(prSelectRes.prSelect[i].number, prSelectRes.prSelect[i].repo)
log('success', `✔ Update PR #${prl[i].number} completed`)
}
Expand All @@ -112,16 +112,18 @@ async function printUpdateRes(res: IPRCheckRes[]) {
})
res.sort((a, b) => Number(a.isNeedUpdate) - Number(b.isNeedUpdate))
res.forEach((item) => {
p.addRow({
'number': chalk.greenBright.bold(`#${item.number}`),
'can merge': item.isNeedUpdate ? chalk.greenBright.bold('true') : chalk.redBright.bold('false'),
'success': item.isNeedUpdate ? chalk.greenBright.bold('true') : chalk.redBright.bold('false'),
'reason': item.isNeedUpdate
? chalk.blueBright.bold('-')
: item.reason === 'not updated' ? chalk.blueBright.bold(item.reason) : chalk.yellowBright.bold(item.reason),
'repo': chalk.blueBright.bold(`<${item.repo}>`),
'title': item.title,
})
if (!isEmptyObj(item)) {
p.addRow({
'number': chalk.greenBright.bold(`#${item.number}`),
'can merge': item.isNeedUpdate ? chalk.greenBright.bold('true') : chalk.redBright.bold('false'),
'success': item.isNeedUpdate ? chalk.greenBright.bold('true') : chalk.redBright.bold('false'),
'reason': item.isNeedUpdate
? chalk.blueBright.bold('-')
: item.reason === 'not updated' ? chalk.blueBright.bold(item.reason) : chalk.yellowBright.bold(item.reason),
'repo': chalk.blueBright.bold(`<${item.repo}>`),
'title': item.title,
})
}
})
p.printTable()
}
Expand Down
1 change: 1 addition & 0 deletions utils/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './log'
export const isEmptyObj = (item: unknown): boolean => JSON.stringify(item) === '{}'

0 comments on commit 773b5fb

Please sign in to comment.