Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
renovate
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
Renovate Bot
renovate
Commits
8de6e56a
Commit
8de6e56a
authored
8 years ago
by
Rhys Arkins
Browse files
Options
Downloads
Patches
Plain Diff
Refactor promises
parent
28ffae2e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/index.js
+45
-38
45 additions, 38 deletions
src/index.js
with
45 additions
and
38 deletions
src/index.js
+
45
−
38
View file @
8de6e56a
...
...
@@ -88,6 +88,16 @@ function updateDependency(depType, depName, currentVersion, nextVersion) {
console
.
log
(
`
${
depName
}
: Skipping due to existing PR found.`
);
return
;
}
return
ensureBranch
()
.
then
(
ensureCommit
)
.
then
(
ensurePr
)
.
catch
(
error
=>
{
console
.
log
(
'
Error updating dependency depName:
'
+
error
);
// Don't throw here - we don't want to stop the other renovations
});
});
function
ensureBranch
()
{
// Save an API call by attempting to create branch without checking for existence first
return
github
.
createBranch
(
branchName
)
.
catch
(
error
=>
{
...
...
@@ -98,48 +108,45 @@ function updateDependency(depType, depName, currentVersion, nextVersion) {
console
.
log
(
'
Response body:
'
+
error
.
response
.
body
);
throw
error
;
}
}).
then
(()
=>
{
// Retrieve the package.json from this renovate branch
return
github
.
getFile
(
packageFile
,
branchName
).
then
(
res
=>
{
const
currentSHA
=
res
.
body
.
sha
;
let
currentFileContent
=
JSON
.
parse
(
new
Buffer
(
res
.
body
.
content
,
'
base64
'
).
toString
());
if
(
currentFileContent
[
depType
][
depName
]
!==
nextVersion
)
{
// Branch is new, or needs version updated
});
}
function
ensureCommit
()
{
// Retrieve the package.json from this renovate branch
return
github
.
getFile
(
packageFile
,
branchName
).
then
(
res
=>
{
const
currentSHA
=
res
.
body
.
sha
;
let
currentFileContent
=
JSON
.
parse
(
new
Buffer
(
res
.
body
.
content
,
'
base64
'
).
toString
());
if
(
currentFileContent
[
depType
][
depName
]
!==
nextVersion
)
{
// Branch is new, or needs version updated
if
(
config
.
verbose
)
{
console
.
log
(
`
${
depName
}
: Updating to
${
nextVersion
}
in branch
${
branchName
}
`
);
}
currentFileContent
[
depType
][
depName
]
=
nextVersion
;
const
newPackageContents
=
JSON
.
stringify
(
currentFileContent
,
null
,
2
)
+
'
\n
'
;
return
github
.
writeFile
(
branchName
,
currentSHA
,
packageFile
,
newPackageContents
,
commitMessage
);
}
else
{
if
(
config
.
verbose
)
{
console
.
log
(
`
${
depName
}
: Already up-to-date in branch
${
branchName
}
`
);
}
return
;
}
});
}
function
ensurePr
()
{
return
github
.
getPr
(
branchName
).
then
(
pr
=>
{
if
(
pr
)
{
if
(
pr
.
title
===
prTitle
&&
pr
.
body
===
prBody
)
{
if
(
config
.
verbose
)
{
console
.
log
(
`
Updating
${
depName
}
to
${
nextVersion
}
in branch
${
branchName
}
`
);
console
.
log
(
`
${
depName
}
: PR #
${
pr
.
number
}
already up-to-date
`
);
}
currentFileContent
[
depType
][
depName
]
=
nextVersion
;
const
newPackageContents
=
JSON
.
stringify
(
currentFileContent
,
null
,
2
)
+
'
\n
'
;
return
github
.
writeFile
(
branchName
,
currentSHA
,
packageFile
,
newPackageContents
,
commitMessage
)
.
then
(()
=>
{
return
ensurePr
(
branchName
,
prTitle
,
prBody
);
});
}
else
{
if
(
config
.
verbose
)
{
console
.
log
(
`
${
depName
}
was already up-to-date in branch
${
branchName
}
`
);
}
// File was up to date. Ensure PR
return
ensurePr
(
branchName
,
prTitle
,
prBody
);
}
});
})
.
catch
(
error
=>
{
console
.
log
(
'
Promise catch
'
);
});
});
}
function
ensurePr
(
branchName
,
prTitle
,
prBody
)
{
return
github
.
getPr
(
branchName
).
then
(
pr
=>
{
if
(
pr
)
{
if
(
pr
.
title
===
prTitle
&&
pr
.
body
===
prBody
)
{
if
(
config
.
verbose
)
{
console
.
log
(
'
PR already up-to-date
'
);
console
.
log
(
`
${
depName
}
: Updating PR #
${
pr
.
number
}
`
);
return
github
.
updatePr
(
pr
.
number
,
prTitle
,
prBody
);
}
}
else
{
console
.
log
(
`Updating PR #
${
pr
.
number
}
`
);
return
github
.
updatePr
(
pr
.
number
,
prTitle
,
prBody
);
return
github
.
createPr
(
branchName
,
prTitle
,
prBody
).
then
((
pr
)
=>
{
console
.
log
(
`
${
depName
}
: Created PR #
${
pr
.
number
}
`
);
});
}
}
}
);
}
);
}
}
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