Skip to content
This repository was archived by the owner on Aug 21, 2019. It is now read-only.

Commit 15f4be6

Browse files
committed
add option for branch
1 parent a8732b4 commit 15f4be6

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

README.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ gitlab-le \
2222
--production `# OPTIONAL - Obtain a real certificate instead of a dummy one and configure your repository to use it`
2323
--path `# OPTIONAL - Absolute path in your repository where challenge files should be uploaded`
2424
--jekyll `# OPTIONAL - Upload challenge files with a Jekyll-compatible YAML front matter` \
25+
--branch `# OPTIONAL - Upload challenge files to this branch, default is the main branch of the repository` \
2526
```
2627

2728
See `gitlab-le --help` for more details.
@@ -77,4 +78,4 @@ However, GitLab does not provide a way to automatically renew certificates, so t
7778

7879
## Automation
7980

80-
Since 10.2, GitLab provides an API to configure HTTPS certificates on a GitLab page, which means `gitlab-le` can be configured to obtain new certificates when your existing ones are about to expire.
81+
Since 10.2, GitLab provides an API to configure HTTPS certificates on a GitLab page, which means `gitlab-le` can be configured to obtain new certificates when your existing ones are about to expire.

args.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,15 @@ module.exports = yargs
3434
describe: 'Obtain a real certificate instead of a dummy one and configure your repository to use it',
3535
type: 'boolean',
3636
default: false
37+
}).option('branch', {
38+
describe: 'Select the branch where the challenge files should be uploaded.',
39+
type: 'string',
40+
default: ''
3741
}).example('$0 --domain example.com www.example.com --email [email protected] --repository https://gitlab.com/foo/example.gitlab.io --token abc123', 'Simple build where all files are served from public/ inside your repository')
3842
.example('$0 --jekyll --path / --domain example.com --email [email protected] --repository https://gitlab.example.com/foo/myrepo --token abc123', 'Jekyll website that serves all valid files in your repository\'s root directory')
3943
.wrap(yargs.terminalWidth())
4044
.check(argv => {
41-
const empty = Object.keys(argv).filter(key => key !== '_' && argv[key].length == 0);
45+
const empty = Object.keys(argv).filter(key => key !== '_' && key !== 'branch' && argv[key].length == 0);
4246
if (empty.length > 0) {
4347
console.error(`Missing required arguments: ${empty.join(', ')}`);
4448
process.exit(1);

lib.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module.exports = (options) => {
4747
});
4848
};
4949

50-
const uploadChallenge = (key, value, repo, domain) => {
50+
const uploadChallenge = (key, value, repo, domain, branch) => {
5151
const challengeContent = options.jekyll ?
5252
`---\nlayout: null\npermalink: /.well-known/acme-challenge/${key}\n---\n${value}` : value;
5353
// Need to bluebird-ify to use .asCallback()
@@ -56,20 +56,20 @@ module.exports = (options) => {
5656
url: `/projects/${repo.id}/repository/files/${filePath}`,
5757
body: {
5858
commit_message: 'Automated Let\'s Encrypt renewal: add challenge',
59-
branch: repo.default_branch,
59+
branch: branch || repo.default_branch,
6060
content: challengeContent,
6161
author_name: 'gitlab-le'
6262
}
6363
})).return([`http://${domain}/.well-known/acme-challenge/${key}`, value]);
6464
};
6565

66-
const deleteChallenges = (key, repo) => {
66+
const deleteChallenges = (key, repo, branch) => {
6767
const filePath = encodeURIComponent(path.posix.resolve('/', options.path, key));
6868
return Promise.resolve(gitlabRequest.delete({
6969
url: `/projects/${repo.id}/repository/files/${filePath}`,
7070
body: {
7171
commit_message: 'Automated Let\'s Encrypt renewal: remove challenge',
72-
branch: repo.default_branch,
72+
branch: branch || repo.default_branch,
7373
author_name: 'gitlab-le'
7474
}
7575
}));
@@ -151,13 +151,13 @@ module.exports = (options) => {
151151
domains: options.domain,
152152
setChallenge: (hostname, key, value, cb) => {
153153
return Promise.resolve(deleteChallengesPromise)
154-
.then(() => uploadChallenge(key, value, repo, hostname))
154+
.then(() => uploadChallenge(key, value, repo, hostname, options.branch))
155155
.tap(res => console.log(`Uploaded challenge file, polling until it is available at ${res[0]}`))
156156
.spread(pollUntilDeployed)
157157
.asCallback(cb);
158158
},
159159
removeChallenge: (hostname, key, cb) => {
160-
return (deleteChallengesPromise = deleteChallenges(key, repo)).finally(() => cb(null));
160+
return (deleteChallengesPromise = deleteChallenges(key, repo, options.branch)).finally(() => cb(null));
161161
}
162162
});
163163
}).tap(cert =>

0 commit comments

Comments
 (0)