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
58da519c
Commit
58da519c
authored
8 years ago
by
Rhys Arkins
Browse files
Options
Downloads
Patches
Plain Diff
Support configurable repository and package file
parent
69fcc11c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/helpers/github.js
+3
-5
3 additions, 5 deletions
src/helpers/github.js
src/index.js
+32
-27
32 additions, 27 deletions
src/index.js
with
35 additions
and
32 deletions
src/helpers/github.js
+
3
−
5
View file @
58da519c
...
@@ -4,12 +4,10 @@ var config = {};
...
@@ -4,12 +4,10 @@ var config = {};
module
.
exports
=
{
module
.
exports
=
{
// Initialize GitHub by getting base branch SHA
// Initialize GitHub by getting base branch SHA
init
:
function
(
token
,
repoName
,
baseBranch
,
verbose
=
fals
e
)
{
init
:
function
(
setConfig
,
repoName
,
packageFil
e
)
{
config
.
token
=
token
;
config
=
setConfig
;
config
.
repoName
=
repoName
;
config
.
repoName
=
repoName
;
config
.
baseBranch
=
baseBranch
;
config
.
packageFile
=
packageFile
;
config
.
verbose
=
verbose
;
config
.
userName
=
repoName
.
split
(
'
/
'
)[
0
];
config
.
userName
=
repoName
.
split
(
'
/
'
)[
0
];
return
ghGot
(
`repos/
${
config
.
repoName
}
/git/refs/head`
,
{
token
:
config
.
token
}).
then
(
res
=>
{
return
ghGot
(
`repos/
${
config
.
repoName
}
/git/refs/head`
,
{
token
:
config
.
token
}).
then
(
res
=>
{
...
...
This diff is collapsed.
Click to expand it.
src/index.js
+
32
−
27
View file @
58da519c
...
@@ -5,15 +5,13 @@ const github = require('./helpers/github');
...
@@ -5,15 +5,13 @@ const github = require('./helpers/github');
const
npm
=
require
(
'
./helpers/npm
'
);
const
npm
=
require
(
'
./helpers/npm
'
);
const
packageJson
=
require
(
'
./helpers/packageJson
'
);
const
packageJson
=
require
(
'
./helpers/packageJson
'
);
// Process arguments
const
repoName
=
process
.
argv
[
2
];
const
packageFile
=
process
.
argv
[
3
]
||
'
package.json
'
;
const
token
=
process
.
env
.
RENOVATE_TOKEN
;
validateArguments
();
const
config
=
initConfig
();
const
config
=
initConfig
();
validateArguments
();
npm
.
init
(
config
);
npm
.
init
(
config
);
const
repoName
=
Object
.
keys
(
config
.
repositories
)[
0
];
const
packageFile
=
config
.
repositories
[
repoName
]
||
'
package.json
'
;
initGitHub
()
initGitHub
()
.
then
(
getPackageFileContents
)
.
then
(
getPackageFileContents
)
.
then
(
determineUpgrades
)
.
then
(
determineUpgrades
)
...
@@ -25,22 +23,6 @@ initGitHub()
...
@@ -25,22 +23,6 @@ initGitHub()
console
.
log
(
'
renovate caught error:
'
+
err
);
console
.
log
(
'
renovate caught error:
'
+
err
);
});
});
function
validateArguments
()
{
// token must be defined
if
(
typeof
token
===
'
undefined
'
)
{
console
.
error
(
'
Error: Environment variable RENOVATE_TOKEN must be defined
'
);
process
.
exit
(
1
);
}
// Check arguments
if
(
process
.
argv
.
length
<
3
||
process
.
argv
.
length
>
4
)
{
console
.
error
(
'
Error: You must specify the GitHub repository and optionally path.
'
);
console
.
log
(
'
Example: node src singapore/renovate
'
);
console
.
log
(
'
Example: node src foo/bar baz/package.json
'
);
process
.
exit
(
1
);
}
}
function
initConfig
()
{
function
initConfig
()
{
const
defaultConfig
=
require
(
'
./defaults
'
);
const
defaultConfig
=
require
(
'
./defaults
'
);
let
customConfig
=
{};
let
customConfig
=
{};
...
@@ -49,19 +31,42 @@ function initConfig() {
...
@@ -49,19 +31,42 @@ function initConfig() {
}
catch
(
e
)
{
}
catch
(
e
)
{
// Do nothing
// Do nothing
}
}
return
Object
.
assign
(
defaultConfig
,
customConfig
);
const
cliConfig
=
{};
if
(
process
.
env
.
RENOVATE_TOKEN
)
{
cliConfig
.
token
=
process
.
env
.
RENOVATE_TOKEN
;
}
// Check if repository name and package file are provided via CLI
const
repoName
=
process
.
argv
[
2
];
const
packageFile
=
process
.
argv
[
3
]
||
'
package.json
'
;
if
(
repoName
)
{
cliConfig
.
repositories
=
{};
cliConfig
.
repositories
[
repoName
]
=
packageFile
;
}
return
Object
.
assign
(
defaultConfig
,
customConfig
,
cliConfig
);
}
function
validateArguments
()
{
// token must be defined
if
(
typeof
config
.
token
===
'
undefined
'
)
{
console
.
error
(
'
Error: A GitHub token must be configured
'
);
process
.
exit
(
1
);
}
// We also need a repository
if
(
typeof
Object
.
keys
(
config
.
repositories
).
length
===
0
)
{
console
.
error
(
'
Error: A repository must be configured
'
);
}
}
}
function
initGitHub
()
{
function
initGitHub
()
{
if
(
config
.
verbose
)
{
if
(
config
.
verbose
)
{
console
.
log
(
'
Initializing GitHub
'
);
console
.
log
(
'
Initializing GitHub
'
);
}
}
return
github
.
init
(
token
,
repoName
,
config
.
baseBranch
,
config
.
verbos
e
);
return
github
.
init
(
config
,
repoName
,
packageFil
e
);
}
}
function
getPackageFileContents
()
{
function
getPackageFileContents
()
{
console
.
log
(
'
Getting package file contents
'
);
console
.
log
(
'
Getting package file contents
'
);
return
github
.
getFileContents
(
packageFile
);
return
github
.
getFileContents
(
config
.
packageFile
);
}
}
function
determineUpgrades
(
packageFileContents
)
{
function
determineUpgrades
(
packageFileContents
)
{
...
@@ -135,7 +140,7 @@ function updateDependency({ upgradeType, depType, depName, currentVersion, newVe
...
@@ -135,7 +140,7 @@ function updateDependency({ upgradeType, depType, depName, currentVersion, newVe
}
}
function
ensureCommit
()
{
function
ensureCommit
()
{
// Retrieve the package.json from this renovate branch
// Retrieve the package.json from this renovate branch
return
github
.
getFile
(
packageFile
,
branchName
).
then
(
res
=>
{
return
github
.
getFile
(
config
.
packageFile
,
branchName
).
then
(
res
=>
{
const
currentSHA
=
res
.
body
.
sha
;
const
currentSHA
=
res
.
body
.
sha
;
const
currentFileContent
=
new
Buffer
(
res
.
body
.
content
,
'
base64
'
).
toString
();
const
currentFileContent
=
new
Buffer
(
res
.
body
.
content
,
'
base64
'
).
toString
();
const
currentJson
=
JSON
.
parse
(
currentFileContent
);
const
currentJson
=
JSON
.
parse
(
currentFileContent
);
...
@@ -148,7 +153,7 @@ function updateDependency({ upgradeType, depType, depName, currentVersion, newVe
...
@@ -148,7 +153,7 @@ function updateDependency({ upgradeType, depType, depName, currentVersion, newVe
return
github
.
writeFile
(
branchName
,
currentSHA
,
packageFile
,
newPackageContents
,
commitMessage
);
return
github
.
writeFile
(
branchName
,
currentSHA
,
packageFile
,
newPackageContents
,
commitMessage
);
}
else
{
}
else
{
if
(
config
.
verbose
)
{
if
(
config
.
verbose
)
{
console
.
log
(
`
${
depName
}
:
Already up-to-date in branch
${
branchName
}
`
);
console
.
log
(
`
${
depName
}
:
branch
${
branchName
}
is already up-to-date
`
);
}
}
return
;
return
;
}
}
...
...
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