Skip to content

Commit 983529a

Browse files
committed
0.1.0: First Release
1 parent 0c78d80 commit 983529a

File tree

10 files changed

+526
-1
lines changed

10 files changed

+526
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

LICENSE

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
The MIT License (MIT)
2+
Copyright (c) 2017 Jumpei Miyata <miyajan777@gmail.com>
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
6+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
8+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,86 @@
11
# node-github-release
2-
NPM package to create and edit releases on Github (and upload artifacts)
2+
3+
CLI to create and edit releases on Github (and upload artifacts)
4+
5+
## Acknowledgement
6+
7+
This tool is greatly inspired by [aktau's go implementation](https://github.com/aktau/github-release). Thank you so, so much!
8+
9+
## Requirement
10+
11+
* Node >= 6
12+
13+
## Usage
14+
15+
```bash
16+
# set your token
17+
export GITHUB_TOKEN=...
18+
19+
# (optional) you can point to a different GitHub host (for GitHub Enterprise)
20+
# export GITHUB_HOST=github.company.com
21+
# export GITHUB_API_PATH_PREFIX=/api/v3
22+
23+
# help
24+
$ github-release --help
25+
26+
# make your tag and upload
27+
$ git tag ... && git push --tags
28+
29+
# check the current tags and existing releases of the repo
30+
$ github-release info -u miyajan -r node-github-release
31+
tags:
32+
- 0.1.0 (commit: https://api.github.com/repos/miyajan/node-github-release/commits/...)
33+
releases:
34+
- 0.1.0, name: '...', description: '...', id: ..., tagged: ... , published: ... , draft: ✔, prerelease: ✗
35+
- artifact: ...
36+
37+
# create a formal release
38+
$ github-release release \
39+
--user miyajan \
40+
--repo node-github-release \
41+
--tag 0.1.0 \
42+
--name "..." \
43+
--description "..." \
44+
--pre-release
45+
46+
# you've made a mistake, but you can edit the release without
47+
# having to delete it first (this also means you can edit without having
48+
# to upload your files again)
49+
$ github-release edit \
50+
--user miyajan \
51+
--repo node-github-release \
52+
--tag 0.1.0 \
53+
--name "..." \
54+
--description "..."
55+
56+
# upload a file
57+
$ github-release upload \
58+
--user miyajan \
59+
--repo node-github-release \
60+
--tag 0.1.0 \
61+
--name "..." \
62+
--file ...
63+
64+
# upload other files...
65+
$ github-release upload ...
66+
67+
# you're not happy with it, so delete it
68+
$ github-release delete \
69+
--user miyajan \
70+
--repo node-github-release \
71+
--tag 0.1.0
72+
```
73+
74+
## Install
75+
76+
```bash
77+
$ npm install -g node-github-release
78+
```
79+
80+
## License
81+
82+
[MIT](https://github.com/miyajan/node-github-release/blob/master/LICENSE)
83+
84+
## Author
85+
86+
[miyajan](https://github.com/miyajan): Jumpei Miyata miyajan777@gmail.com

bin/github-release.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env node
2+
3+
const CommandLine = require('../lib/cli');
4+
const cli = new CommandLine(process);
5+
cli.execute();

index.js

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
const GitHub = require('github-api');
2+
const GitHubApi = require('github');
3+
const Tag = require('./lib/tag');
4+
const Release = require('./lib/release');
5+
const Info = require('./lib/info');
6+
7+
class GitHubRelease {
8+
constructor(token, host, pathPrefix) {
9+
this.github = new GitHubApi({
10+
host: host,
11+
pathPrefix: pathPrefix
12+
});
13+
this.github.authenticate({
14+
type: 'token',
15+
token: token
16+
});
17+
}
18+
19+
info(user, repo) {
20+
const tags = this.github.repos.getTags({
21+
owner: user,
22+
repo: repo,
23+
per_page: 100 // TODO: support for pagination
24+
});
25+
const releases = this.github.repos.getReleases({
26+
owner: user,
27+
repo: repo,
28+
per_page: 100 // TODO: support for pagination
29+
});
30+
return Promise.all([tags, releases]).then(resps => {
31+
const tagsResp = resps[0];
32+
const releasesResp = resps[1];
33+
const tags = tagsResp.data.map(obj => {
34+
return new Tag(obj.name, obj.commit.url);
35+
});
36+
const releases = releasesResp.data.map(obj => {
37+
return new Release(obj.id, obj.tag_name, obj.name, obj.body, obj.draft, obj.prerelease, obj.created_at, obj.published_at);
38+
});
39+
return new Info(tags, releases);
40+
});
41+
}
42+
43+
release(user, repo, tag, name, description, target, draft, preRelease) {
44+
const options = {
45+
owner: user,
46+
repo: repo,
47+
tag_name: tag
48+
};
49+
if (name !== undefined) {
50+
options.name = name;
51+
}
52+
if (target !== undefined) {
53+
options.target_commitish = target;
54+
}
55+
if (draft !== undefined) {
56+
options.draft = draft;
57+
}
58+
if (preRelease !== undefined) {
59+
options.prerelease = preRelease;
60+
}
61+
if (description !== undefined) {
62+
options.body = description;
63+
}
64+
return this.github.repos.createRelease(options);
65+
}
66+
67+
edit(user, repo, tag, name, description, target, draft, preRelease) {
68+
return this.github.repos.getReleaseByTag({
69+
owner: user,
70+
repo: repo,
71+
tag: tag
72+
}).catch(err => {
73+
if (err.code === 404) {
74+
throw new Error(`Error: release not found (user: ${user}, repo: ${repo}, tag: ${tag})`);
75+
}
76+
throw err;
77+
}).then(res => {
78+
const id = res.data.id;
79+
const options = {
80+
owner: user,
81+
repo: repo,
82+
id: id,
83+
tag_name: tag
84+
};
85+
if (name !== undefined) {
86+
options.name = name;
87+
}
88+
if (target !== undefined) {
89+
options.target = target;
90+
}
91+
if (draft !== undefined) {
92+
options.draft = draft;
93+
}
94+
if (preRelease !== undefined) {
95+
options.prerelease = preRelease;
96+
}
97+
if (description !== undefined) {
98+
options.body = description;
99+
}
100+
return this.github.repos.editRelease(options);
101+
});
102+
}
103+
104+
upload(user, repo, tag, name, label, file) {
105+
return this.github.repos.getReleaseByTag({
106+
owner: user,
107+
repo: repo,
108+
tag: tag
109+
}).catch(err => {
110+
if (err.code === 404) {
111+
throw new Error(`Error: release not found (user: ${user}, repo: ${repo}, tag: ${tag})`);
112+
}
113+
throw err;
114+
}).then(res => {
115+
const id = res.data.id;
116+
const options = {
117+
owner: user,
118+
repo: repo,
119+
id: id,
120+
filePath: file,
121+
name: name
122+
};
123+
if (label !== undefined) {
124+
options.label = label;
125+
}
126+
return this.github.repos.uploadAsset(options);
127+
});
128+
}
129+
130+
destroy(user, repo, tag) {
131+
return this.github.repos.getReleaseByTag({
132+
owner: user,
133+
repo: repo,
134+
tag: tag
135+
}).catch(err => {
136+
if (err.code === 404) {
137+
throw new Error(`Error: release not found (user: ${user}, repo: ${repo}, tag: ${tag})`);
138+
}
139+
throw err;
140+
}).then(res => {
141+
const id = res.data.id;
142+
const options = {
143+
owner: user,
144+
repo: repo,
145+
id: id
146+
};
147+
return this.github.repos.deleteRelease(options);
148+
});
149+
}
150+
}
151+
152+
module.exports = GitHubRelease;

0 commit comments

Comments
 (0)