Skip to content

Commit

Permalink
Enable multiple instances of pull[bot] (#1)
Browse files Browse the repository at this point in the history
Signed-off-by: Ljubo Nikolić <[email protected]>
  • Loading branch information
ljubon authored Jul 29, 2024
1 parent ac1e363 commit 9be7b99
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
3 changes: 2 additions & 1 deletion lib/get-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ async function getDefaultConfig (context) {
{
base: `${defaultBranch}`,
upstream: `${upstreamOwner}:${defaultBranch}`,
mergeMethod: process.env.DEFAULT_MERGE_METHOD || 'hardreset'
mergeMethod: process.env.DEFAULT_MERGE_METHOD || 'hardreset',
mergeUnstable: process.env.MERGE_UNSTABLE || false
}
]
}
Expand Down
4 changes: 2 additions & 2 deletions lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ exports.getPRTitle = (ref, upstream) =>

exports.getPRBody = (repoPath, prNumber) =>
(prNumber
? `See [Commits](/${repoPath}/pull/${prNumber}/commits) and [Changes](/${repoPath}/pull/${prNumber}/files) for more details.\n\n-----\nCreated by [<img src="https://prod.download/pull-18h-svg" valign="bottom"/> **pull[bot]**](https://github.com/wei/pull)`
: 'See Commits and Changes for more details.\n\n-----\nCreated by [<img src="https://prod.download/pull-18h-svg" valign="bottom"/> **pull[bot]**](https://github.com/wei/pull)') +
? `See [Commits](/${repoPath}/pull/${prNumber}/commits) and [Changes](/${repoPath}/pull/${prNumber}/files) for more details.\n\n-----\nCreated by [<img src="https://prod.download/pull-18h-svg" valign="bottom"/> **${process.env.APP_NAME}[bot]**](https://github.com/wei/pull)`
: `See Commits and Changes for more details.\n\n-----\nCreated by [<img src="https://prod.download/pull-18h-svg" valign="bottom"/> **${process.env.APP_NAME}[bot]**](https://github.com/wei/pull)`) +
'\n\n_Can you help keep this open source service alive? **[💖 Please sponsor : )](https://prod.download/pull-pr-sponsor)**_'
6 changes: 3 additions & 3 deletions lib/pull.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ module.exports = class Pull {

if (rule && rule.mergeMethod !== 'none' &&
incomingPR.state === 'open' &&
incomingPR.user.login === 'pull[bot]' &&
incomingPR.user.login === `${process.env.APP_NAME}[bot]` &&
incomingPR.mergeable !== false // mergeable can be null, in which case we can proceed to wait and retry
) {
const mergeableStatus = (incomingPR.mergeable && (incomingPR.mergeable_state === 'clean' || (incomingPR.mergeable_state === 'unstable' && rule.mergeUnstable)))
Expand Down Expand Up @@ -156,7 +156,7 @@ module.exports = class Pull {
const res = await this.github.issues.listForRepo({
owner: this.config.owner,
repo: this.config.repo,
creator: 'pull[bot]',
creator: `${process.env.APP_NAME}[bot]`,
per_page: 100
})
if (res.data.length > 0) {
Expand All @@ -168,7 +168,7 @@ module.exports = class Pull {
})
if (
pr.data &&
pr.data.user.login === 'pull[bot]' &&
pr.data.user.login === `${process.env.APP_NAME}[bot]` &&
pr.data.base.label.replace(`${this.config.owner}:`, '') === base.replace(`${this.config.owner}:`, '') &&
pr.data.head.label.replace(`${this.config.owner}:`, '') === head.replace(`${this.config.owner}:`, '')
) {
Expand Down
2 changes: 1 addition & 1 deletion lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const GITHUB_CREDENTIALS = (process.env.CLIENT_ID && process.env.CLIENT_SECRET)
: ''
const getJSON = uri => requestPromise({
uri,
headers: { 'User-Agent': process.env.APP_ID || 'pull[bot]' },
headers: { 'User-Agent': process.env.APP_ID || `${process.env.APP_NAME}[bot]` },
json: true
})

Expand Down
34 changes: 17 additions & 17 deletions test/pull.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ describe('pull - routineCheck', () => {
base: { ref: 'master' },
head: { ref: 'master', label: 'upstream:master', sha: 'sha1-placeholder-12' },
state: 'open',
user: { login: 'pull[bot]' },
user: { login: `${process.env.APP_NAME}[bot]` },
mergeable: true,
mergeable_state: 'clean'
}
Expand Down Expand Up @@ -191,7 +191,7 @@ describe('pull - routineCheck', () => {
base: { ref: 'master', label: 'wei:master' },
head: { ref: 'master', label: 'upstream:master', sha: 'sha1-placeholder-12' },
state: 'open',
user: { login: 'pull[bot]' },
user: { login: `${process.env.APP_NAME}[bot]` },
mergeable: true,
rebaseable: true,
mergeable_state: 'clean'
Expand All @@ -204,7 +204,7 @@ describe('pull - routineCheck', () => {
base: { ref: 'feature/new-1', label: 'wei:feature/new-1' },
head: { ref: 'dev', label: 'upstream:dev', sha: 'sha1-placeholder-13' },
state: 'open',
user: { login: 'pull[bot]' },
user: { login: `${process.env.APP_NAME}[bot]` },
mergeable: true,
rebaseable: true,
mergeable_state: 'clean'
Expand All @@ -217,7 +217,7 @@ describe('pull - routineCheck', () => {
base: { ref: 'hotfix/bug-1', label: 'wei:hotfix/bug-1' },
head: { ref: 'dev', label: 'upstream:dev', sha: 'sha1-placeholder-14' },
state: 'open',
user: { login: 'pull[bot]' },
user: { login: `${process.env.APP_NAME}[bot]` },
mergeable: true,
rebaseable: true,
mergeable_state: 'clean'
Expand Down Expand Up @@ -272,7 +272,7 @@ describe('pull - routineCheck', () => {
base: { ref: 'master', label: 'wei:master' },
head: { ref: 'master', label: 'upstream:master', sha: 'sha1-placeholder' },
state: 'open',
user: { login: 'pull[bot]' },
user: { login: `${process.env.APP_NAME}[bot]` },
mergeable: true,
rebaseable: true,
mergeable_state: 'clean'
Expand Down Expand Up @@ -325,7 +325,7 @@ describe('pull - checkAutoMerge', () => {
base: { ref: 'master', label: 'wei:master' },
head: { ref: 'master', label: 'upstream:master' },
state: 'open',
user: { login: 'pull[bot]' },
user: { login: `${process.env.APP_NAME}[bot]` },
mergeable: true,
rebaseable: true,
mergeable_state: 'clean'
Expand All @@ -341,7 +341,7 @@ describe('pull - checkAutoMerge', () => {
base: { ref: 'feature/new-1' },
head: { ref: 'dev', label: 'upstream:dev', sha: 'sha1-placeholder' },
state: 'open',
user: { login: 'pull[bot]' },
user: { login: `${process.env.APP_NAME}[bot]` },
mergeable: null,
rebaseable: false,
mergeable_state: 'unknown'
Expand All @@ -363,7 +363,7 @@ describe('pull - checkAutoMerge', () => {
base: { ref: 'hotfix/bug-1' },
head: { ref: 'dev', label: 'upstream:dev', sha: 'sha1-placeholder' },
state: 'open',
user: { login: 'pull[bot]' },
user: { login: `${process.env.APP_NAME}[bot]` },
mergeable: null,
mergeable_state: 'unknown'
})
Expand All @@ -384,7 +384,7 @@ describe('pull - checkAutoMerge', () => {
base: { ref: 'feature/new-1' },
head: { ref: 'dev', label: 'upstream:dev', sha: 'sha1-placeholder' },
state: 'open',
user: { login: 'pull[bot]' },
user: { login: `${process.env.APP_NAME}[bot]` },
mergeable: null,
rebaseable: false,
mergeable_state: 'unknown'
Expand All @@ -403,7 +403,7 @@ describe('pull - checkAutoMerge', () => {
base: { ref: 'feature/new-1' },
head: { ref: 'dev', label: 'upstream:dev', sha: 'sha1-placeholder' },
state: 'open',
user: { login: 'pull[bot]' },
user: { login: `${process.env.APP_NAME}[bot]` },
mergeable: false
}, { conflictReviewers: ['wei', 'saurabh702'] })

Expand All @@ -429,7 +429,7 @@ describe('pull - checkAutoMerge', () => {
base: { ref: 'feature/new-1' },
head: { ref: 'dev', label: 'upstream:dev', sha: 'sha1-placeholder' },
state: 'open',
user: { login: 'pull[bot]' },
user: { login: `${process.env.APP_NAME}[bot]` },
mergeable: null,
mergeable_state: 'unknown'
}, { isMergeableMaxRetries: 2 })
Expand All @@ -448,7 +448,7 @@ describe('pull - checkAutoMerge', () => {
base: { ref: 'dev' },
head: { ref: 'master', label: 'wei:master', sha: 'sha1-placeholder' },
state: 'open',
user: { login: 'pull[bot]' },
user: { login: `${process.env.APP_NAME}[bot]` },
mergeable: true,
rebaseable: false,
mergeable_state: 'unstable'
Expand All @@ -468,7 +468,7 @@ describe('pull - checkAutoMerge', () => {
base: { ref: 'hotfix/bug-1' },
head: { ref: 'dev', label: 'upstream:dev', sha: 'sha1-placeholder' },
state: 'open',
user: { login: 'pull[bot]' },
user: { login: `${process.env.APP_NAME}[bot]` },
mergeable: null,
rebaseable: false,
mergeable_state: 'unknown'
Expand All @@ -490,7 +490,7 @@ describe('pull - checkAutoMerge', () => {
base: { ref: 'dev' },
head: { ref: 'master', label: 'wei:master', sha: 'sha1-placeholder' },
state: 'open',
user: { login: 'pull[bot]' },
user: { login: `${process.env.APP_NAME}[bot]` },
mergeable: null,
rebaseable: false,
mergeable_state: 'unknown'
Expand All @@ -511,7 +511,7 @@ describe('pull - checkAutoMerge', () => {
base: { ref: 'dev' },
head: { ref: 'master', label: 'wei:master', sha: 'sha1-placeholder' },
state: 'open',
user: { login: 'pull[bot]' },
user: { login: `${process.env.APP_NAME}[bot]` },
mergeable: null,
rebaseable: false,
mergeable_state: 'unknown'
Expand All @@ -532,7 +532,7 @@ describe('pull - checkAutoMerge', () => {
base: { ref: 'dev' },
head: { ref: 'master', label: 'wei:master', sha: 'sha1-placeholder' },
state: 'open',
user: { login: 'pull[bot]' },
user: { login: `${process.env.APP_NAME}[bot]` },
mergeable: null,
rebaseable: false,
mergeable_state: 'unknown'
Expand All @@ -553,7 +553,7 @@ describe('pull - checkAutoMerge', () => {
base: { ref: 'dev' },
head: { ref: 'master', label: 'wei:master', sha: 'sha1-placeholder' },
state: 'open',
user: { login: 'pull[bot]' },
user: { login: `${process.env.APP_NAME}[bot]` },
mergeable: null,
rebaseable: false,
mergeable_state: 'unknown'
Expand Down

0 comments on commit 9be7b99

Please sign in to comment.