Skip to content

Commit

Permalink
feat: update release-notes for open branches too when pattern matches
Browse files Browse the repository at this point in the history
  • Loading branch information
DaRaFF committed Oct 19, 2020
1 parent 8ad9268 commit 0fc40d6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cli.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node
console.log('release-notes-patch -> v1.2.7 (removed octokit)')
console.log('release-notes-patch -> v1.3.0 (patch commit for open branches too)')
const argv = require('yargs')
.demandOption(['token', 'owner', 'repo', 'sha', 'tag'])
.help(false)
Expand Down
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ module.exports = async ({token, owner, repo, sha, tag} = {}) => {
}

const path = `releases/${release.branchName}.md`
const releaseNote = await getReleaseNote({
const {releaseNote, branchName} = await getReleaseNote({
owner: 'livingdocsIO',
repo: 'livingdocs-release-notes',
path,
token
token,
releaseName: release.branchName
})

// base64 to string
Expand All @@ -47,7 +48,8 @@ module.exports = async ({token, owner, repo, sha, tag} = {}) => {
path,
message: `chore: update patch release notes of ${release.branchName}.md with tag ${tag}`,
content: parsedBase64ReleaseNote,
sha: releaseNote.sha
sha: releaseNote.sha,
branch: branchName
})

return `update of release-notes with tag ${tag} at ${releaseNote.html_url} sucessfull`
Expand Down
26 changes: 19 additions & 7 deletions lib/get_release_note.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
const getContent = require('./git/get_content')

module.exports = async ({owner, repo, path, token}) => {
module.exports = async ({owner, repo, path, token, releaseName}) => {
let releaseNote
try {
const releaseNote = await getContent({
releaseNote = await getContent({
owner,
repo,
token,
path
path,
branch: 'master'
})
return releaseNote

return {releaseNote, branchName: 'master'}
} catch (error) {
console.log(error)
throw new Error(`${path} not found at https://github.com/livingdocsIO/livingdocs-release-notes`)
try {
releaseNote = await getContent({
owner,
repo,
token,
path,
branch: releaseName
})
return {releaseNote, branchName: releaseName}
} catch (error) {
console.log(error)
throw new Error(`${path} not found at https://github.com/livingdocsIO/livingdocs-release-notes`)
}
}
}
4 changes: 2 additions & 2 deletions lib/git/get_content.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ var request = require('request-promise');
//
// @return
module.exports = async ({
owner, repo, token, path
owner, repo, token, path, branch='master'
}) => {
try {
return await request({
method: 'GET',
uri: `https://api.github.com/repos/${owner}/${repo}/contents/${path}`,
uri: `https://api.github.com/repos/${owner}/${repo}/contents/${path}?ref=${branch}`,
headers: {
'Accept': 'application/vnd.github.v3+json',
'Authorization': `token ${token}`,
Expand Down

0 comments on commit 0fc40d6

Please sign in to comment.