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
32a9993b
Commit
32a9993b
authored
8 years ago
by
Rhys Arkins
Browse files
Options
Downloads
Patches
Plain Diff
Refactor config helper
parent
886cc20d
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/helpers/configurator.js
+74
-0
74 additions, 0 deletions
src/helpers/configurator.js
src/index.js
+12
-88
12 additions, 88 deletions
src/index.js
with
86 additions
and
88 deletions
src/helpers/configurator.js
0 → 100644
+
74
−
0
View file @
32a9993b
const
winston
=
require
(
'
winston
'
);
// Add the logger
const
logger
=
new
(
winston
.
Logger
)({
transports
:
[
// colorize the output to the console
new
(
winston
.
transports
.
Console
)({
colorize
:
true
}),
],
});
module
.
exports
=
{
// This function reads in all configs and merges them
init
(
argv
)
{
/* eslint-disable global-require */
const
defaultConfig
=
require
(
'
../defaults
'
);
let
customConfig
=
{};
try
{
customConfig
=
require
(
'
../config
'
);
}
catch
(
err
)
{
// Do nothing
}
/* eslint-enable global-require */
const
cliConfig
=
{};
if
(
process
.
env
.
LOG_LEVEL
)
{
cliConfig
.
logLevel
=
process
.
env
.
LOG_LEVEL
;
}
if
(
process
.
env
.
RENOVATE_TOKEN
)
{
cliConfig
.
token
=
process
.
env
.
RENOVATE_TOKEN
;
}
// Check if repository name and package file are provided via CLI
const
repoName
=
argv
[
2
];
const
packageFile
=
argv
[
3
]
||
'
package.json
'
;
if
(
repoName
)
{
cliConfig
.
repositories
=
[
{
name
:
repoName
,
packageFiles
:
[
packageFile
],
},
];
}
const
config
=
Object
.
assign
(
defaultConfig
,
customConfig
,
cliConfig
);
// First, convert any strings to objects
config
.
repositories
.
forEach
((
repo
,
index
)
=>
{
if
(
typeof
repo
===
'
string
'
)
{
config
.
repositories
[
index
]
=
{
name
:
repo
};
}
});
// Add 'package.json' if missing
config
.
repositories
.
forEach
((
repo
,
index
)
=>
{
if
(
!
repo
.
packageFiles
||
!
repo
.
packageFiles
.
length
)
{
config
.
repositories
[
index
].
packageFiles
=
[
'
package.json
'
];
}
});
// Winston log level can be controlled via config or env
if
(
config
.
logLevel
)
{
logger
.
level
=
config
.
logLevel
;
}
logger
.
verbose
(
config
);
config
.
logger
=
logger
;
// token must be defined
if
(
typeof
config
.
token
===
'
undefined
'
)
{
logger
.
error
(
'
Error: A GitHub token must be configured
'
);
process
.
exit
(
1
);
}
// We also need a repository
if
(
!
config
.
repositories
||
config
.
repositories
.
length
===
0
)
{
logger
.
error
(
'
Error: At least one repository must be configured
'
);
}
return
config
;
},
};
This diff is collapsed.
Click to expand it.
src/index.js
+
12
−
88
View file @
32a9993b
const
semver
=
require
(
'
semver
'
);
const
winston
=
require
(
'
winston
'
);
const
github
=
require
(
'
./helpers/github
'
);
const
configurator
=
require
(
'
./helpers/configurator
'
);
const
npm
=
require
(
'
./helpers/npm
'
);
const
packageJson
=
require
(
'
./helpers/packageJson
'
);
const
config
=
initConfig
(
);
const
config
=
configurator
.
init
(
process
.
argv
);
const
logger
=
config
.
logger
;
logger
.
verbose
(
`config =
${
JSON
.
stringify
(
config
)}
`
);
validateArguments
();
// Initialize npm
npm
.
init
(
config
);
// Initialize our promise chain
...
...
@@ -16,94 +16,18 @@ let p = Promise.resolve();
// Queue up each repo/package combination
config
.
repositories
.
forEach
((
repo
)
=>
{
const
repoName
=
repo
.
name
;
repo
.
packageFiles
.
forEach
((
packageFile
)
=>
{
p
=
p
.
then
(()
=>
processRepoPackageFile
(
repo
N
ame
,
packageFile
));
p
=
p
.
then
(()
=>
processRepoPackageFile
(
repo
.
n
ame
,
packageFile
));
});
});
// Print something nice once the chain is done
p
.
then
(()
=>
{
// eslint-disable-next-line promise/always-return
if
(
config
.
repositories
.
length
>
1
)
{
logger
.
info
(
'
All repos done
'
);
}
p
.
then
(()
=>
{
logger
.
info
(
'
Renovate finished
'
);
})
.
catch
((
error
)
=>
{
logger
.
error
(
`Unexpected error:
${
error
}
`
);
});
// This function reads in all configs and merges them
function
initConfig
()
{
/* eslint-disable global-require */
const
defaultConfig
=
require
(
'
./defaults
'
);
let
customConfig
=
{};
try
{
customConfig
=
require
(
'
./config
'
);
}
catch
(
err
)
{
// Do nothing
}
/* eslint-enable global-require */
const
cliConfig
=
{};
if
(
process
.
env
.
LOG_LEVEL
)
{
cliConfig
.
logLevel
=
process
.
env
.
LOG_LEVEL
;
}
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
=
[
{
name
:
repoName
,
packageFiles
:
[
packageFile
],
},
];
}
const
combinedConfig
=
Object
.
assign
(
defaultConfig
,
customConfig
,
cliConfig
);
// First, convert any strings to objects
combinedConfig
.
repositories
.
forEach
((
repo
,
index
)
=>
{
if
(
typeof
repo
===
'
string
'
)
{
combinedConfig
.
repositories
[
index
]
=
{
name
:
repo
};
}
});
// Add 'package.json' if missing
combinedConfig
.
repositories
.
forEach
((
repo
,
index
)
=>
{
if
(
!
repo
.
packageFiles
||
!
repo
.
packageFiles
.
length
)
{
combinedConfig
.
repositories
[
index
].
packageFiles
=
[
'
package.json
'
];
}
});
// Add the logger
combinedConfig
.
logger
=
new
(
winston
.
Logger
)({
transports
:
[
// colorize the output to the console
new
(
winston
.
transports
.
Console
)({
colorize
:
true
}),
],
});
// Winston log level can be controlled via config or env
if
(
combinedConfig
.
logLevel
)
{
combinedConfig
.
logger
.
level
=
combinedConfig
.
logLevel
;
}
return
combinedConfig
;
}
// This function makes sure we have a token and at least one repository
function
validateArguments
()
{
// token must be defined
if
(
typeof
config
.
token
===
'
undefined
'
)
{
logger
.
error
(
'
Error: A GitHub token must be configured
'
);
process
.
exit
(
1
);
}
// We also need a repository
if
(
!
config
.
repositories
||
config
.
repositories
.
length
===
0
)
{
logger
.
error
(
'
Error: At least one repository must be configured
'
);
}
}
// This function manages the queue per-package file
function
processRepoPackageFile
(
repoName
,
packageFile
)
{
return
initGitHub
(
repoName
,
packageFile
)
...
...
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