Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
renovate
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SmartDataLab
public
applications
renovate
Commits
8e81a647
Commit
8e81a647
authored
6 years ago
by
Rhys Arkins
Browse files
Options
Downloads
Patches
Plain Diff
refactor: lazy load branch status to reduce requests
parent
80463651
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/workers/pr/index.js
+30
-13
30 additions, 13 deletions
lib/workers/pr/index.js
with
30 additions
and
13 deletions
lib/workers/pr/index.js
+
30
−
13
View file @
8e81a647
...
@@ -19,16 +19,23 @@ async function ensurePr(prConfig) {
...
@@ -19,16 +19,23 @@ async function ensurePr(prConfig) {
logger
.
debug
(
'
Found existing PR
'
);
logger
.
debug
(
'
Found existing PR
'
);
}
}
config
.
upgrades
=
[];
config
.
upgrades
=
[];
const
branchStatus
=
await
platform
.
getBranchStatus
(
branchName
,
config
.
requiredStatusChecks
);
if
(
config
.
lockFileErrors
&&
config
.
lockFileErrors
.
length
)
{
if
(
config
.
lockFileErrors
&&
config
.
lockFileErrors
.
length
)
{
logger
.
debug
(
'
Forcing PR because of lock file errors
'
);
logger
.
debug
(
'
Forcing PR because of lock file errors
'
);
config
.
forcePr
=
true
;
config
.
forcePr
=
true
;
}
}
let
branchStatus
;
async
function
getBranchStatus
()
{
if
(
!
branchStatus
)
{
branchStatus
=
await
platform
.
getBranchStatus
(
branchName
,
config
.
requiredStatusChecks
);
}
return
branchStatus
;
}
// Only create a PR if a branch automerge has failed
// Only create a PR if a branch automerge has failed
if
(
if
(
config
.
automerge
===
true
&&
config
.
automerge
===
true
&&
...
@@ -36,9 +43,12 @@ async function ensurePr(prConfig) {
...
@@ -36,9 +43,12 @@ async function ensurePr(prConfig) {
!
config
.
forcePr
!
config
.
forcePr
)
{
)
{
logger
.
debug
(
logger
.
debug
(
`Branch is configured for branch automerge, branch
S
tatus is:
${
b
ranchStatus
}
`
`Branch is configured for branch automerge, branch
s
tatus
)
is:
${
await
getB
ranchStatus
()
}
`
);
);
if
(
branchStatus
===
'
pending
'
||
branchStatus
===
'
running
'
)
{
if
(
(
await
getBranchStatus
())
===
'
pending
'
||
(
await
getBranchStatus
())
===
'
running
'
)
{
logger
.
debug
(
'
Checking how long this branch has been pending
'
);
logger
.
debug
(
'
Checking how long this branch has been pending
'
);
const
lastCommitTime
=
await
platform
.
getBranchLastCommitTime
(
branchName
);
const
lastCommitTime
=
await
platform
.
getBranchLastCommitTime
(
branchName
);
const
currentTime
=
new
Date
();
const
currentTime
=
new
Date
();
...
@@ -51,7 +61,7 @@ async function ensurePr(prConfig) {
...
@@ -51,7 +61,7 @@ async function ensurePr(prConfig) {
config
.
forcePr
=
true
;
config
.
forcePr
=
true
;
}
}
}
}
if
(
config
.
forcePr
||
b
ranchStatus
===
'
failure
'
)
{
if
(
config
.
forcePr
||
(
await
getB
ranchStatus
())
===
'
failure
'
)
{
logger
.
debug
(
`Branch tests failed, so will create PR`
);
logger
.
debug
(
`Branch tests failed, so will create PR`
);
}
else
{
}
else
{
return
null
;
return
null
;
...
@@ -59,8 +69,10 @@ async function ensurePr(prConfig) {
...
@@ -59,8 +69,10 @@ async function ensurePr(prConfig) {
}
}
if
(
config
.
prCreation
===
'
status-success
'
)
{
if
(
config
.
prCreation
===
'
status-success
'
)
{
logger
.
debug
(
'
Checking branch combined status
'
);
logger
.
debug
(
'
Checking branch combined status
'
);
if
(
branchStatus
!==
'
success
'
)
{
if
((
await
getBranchStatus
())
!==
'
success
'
)
{
logger
.
debug
(
`Branch status is "
${
branchStatus
}
" - not creating PR`
);
logger
.
debug
(
`Branch status is "
${
await
getBranchStatus
()}
" - not creating PR`
);
return
null
;
return
null
;
}
}
logger
.
debug
(
'
Branch status success
'
);
logger
.
debug
(
'
Branch status success
'
);
...
@@ -70,8 +82,13 @@ async function ensurePr(prConfig) {
...
@@ -70,8 +82,13 @@ async function ensurePr(prConfig) {
!
config
.
forcePr
!
config
.
forcePr
)
{
)
{
logger
.
debug
(
'
Checking branch combined status
'
);
logger
.
debug
(
'
Checking branch combined status
'
);
if
(
branchStatus
===
'
pending
'
||
branchStatus
===
'
running
'
)
{
if
(
logger
.
debug
(
`Branch status is "
${
branchStatus
}
" - checking timeout`
);
(
await
getBranchStatus
())
===
'
pending
'
||
(
await
getBranchStatus
())
===
'
running
'
)
{
logger
.
debug
(
`Branch status is "
${
await
getBranchStatus
()}
" - checking timeout`
);
const
lastCommitTime
=
await
platform
.
getBranchLastCommitTime
(
branchName
);
const
lastCommitTime
=
await
platform
.
getBranchLastCommitTime
(
branchName
);
const
currentTime
=
new
Date
();
const
currentTime
=
new
Date
();
const
millisecondsPerHour
=
1000
*
60
*
60
;
const
millisecondsPerHour
=
1000
*
60
*
60
;
...
@@ -205,7 +222,7 @@ async function ensurePr(prConfig) {
...
@@ -205,7 +222,7 @@ async function ensurePr(prConfig) {
try
{
try
{
if
(
existingPr
)
{
if
(
existingPr
)
{
logger
.
debug
(
'
Processing existing PR
'
);
logger
.
debug
(
'
Processing existing PR
'
);
if
(
config
.
automerge
&&
b
ranchStatus
===
'
failure
'
)
{
if
(
config
.
automerge
&&
(
await
getB
ranchStatus
())
===
'
failure
'
)
{
logger
.
debug
(
`Setting assignees and reviewers as status checks failed`
);
logger
.
debug
(
`Setting assignees and reviewers as status checks failed`
);
await
addAssigneesReviewers
(
config
,
existingPr
);
await
addAssigneesReviewers
(
config
,
existingPr
);
}
}
...
@@ -291,7 +308,7 @@ async function ensurePr(prConfig) {
...
@@ -291,7 +308,7 @@ async function ensurePr(prConfig) {
platform
.
ensureComment
(
pr
.
number
,
subject
,
content
);
platform
.
ensureComment
(
pr
.
number
,
subject
,
content
);
}
}
// Skip assign and review if automerging PR
// Skip assign and review if automerging PR
if
(
config
.
automerge
&&
b
ranchStatus
!==
'
failure
'
)
{
if
(
config
.
automerge
&&
(
await
getB
ranchStatus
())
!==
'
failure
'
)
{
logger
.
debug
(
logger
.
debug
(
`Skipping assignees and reviewers as automerge=
${
config
.
automerge
}
`
`Skipping assignees and reviewers as automerge=
${
config
.
automerge
}
`
);
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment