Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
fix: add --file parameter to define onto which file you want to add a…
Browse files Browse the repository at this point in the history
…n empty space for a bump pr
  • Loading branch information
DaRaFF committed Sep 23, 2020
1 parent d88e57d commit 0f3b059
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 23 deletions.
5 changes: 5 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ const argv = require('yargs')
description: 'gh token to auto approve the opened pull request',
type: 'string'
})
.option('file', {
description: 'append an empty space space to this file (one needs a file diff to create a bump PR)',
type: 'string',
default: 'README.md'
})
.help(false)
.version(false)
.argv
Expand Down
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const _ = require('lodash')
const semver = require('semver')
const gitGetTags = require('./lib/git/get_tags')
const gitGetReadme = require('./lib/git/get_readme')
const gitGetContent = require('./lib/git/get_content')
const gitCreateBranch = require('./lib/git/create_branch')
const updateContent = require('./lib/git/update_content')
const createPullRequest = require('./lib/git/create_pull_request')
Expand All @@ -28,14 +28,15 @@ const getHighestTag = async ({repo, owner, token}) => {
}

// main application
module.exports = async ({owner, repo, ghToken, ghApprovalToken}) => {
module.exports = async ({owner, repo, ghToken, ghApprovalToken, file}) => {
const token = ghToken

if (token === ghApprovalToken) throw new Error('gh-approval-token token must be different to the gh-token')
const baseTagCommit = await getHighestTag({repo, owner, token})

// get README.md
const readmeBase64Obj = await gitGetReadme({owner, repo, token})
const readmeBase64Obj = await gitGetContent({owner, repo, token, path: file})
console.log('readmeBase64Obj', readmeBase64Obj)

// add an empty line to the readme to have a code diff for the upcoming pull request
const readme = Buffer.from(readmeBase64Obj.content, 'base64').toString('ascii')
Expand Down
23 changes: 23 additions & 0 deletions lib/git/get_content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var request = require('request-promise');

// https://docs.github.com/en/rest/reference/repos#get-repository-content
//
// @return
module.exports = async ({
owner, repo, token, path
}) => {
try {
return await request({
method: 'GET',
uri: `https://api.github.com/repos/${owner}/${repo}/contents/${path}`,
headers: {
'Accept': 'application/vnd.github.v3+json',
'Authorization': `token ${token}`,
'User-Agent': 'Request-Promise',
},
json: true
})
} catch (error) {
throw error
}
}
18 changes: 0 additions & 18 deletions lib/git/get_readme.js

This file was deleted.

7 changes: 5 additions & 2 deletions lib/git/get_tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ module.exports = async ({owner, repo, token, page = 1, per_page = 10}) => {
try {
return await request({
uri: `https://api.github.com/repos/${owner}/${repo}/tags`,
qs: { access_token: token, page, per_page },
headers: { 'User-Agent': 'Request-Promise' },
qs: { page, per_page },
headers: {
'Authorization': `token ${token}`,
'User-Agent': 'Request-Promise',
},
json: true
})

Expand Down
1 change: 1 addition & 0 deletions lib/git/update_content.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = async ({
uri: `https://api.github.com/repos/${owner}/${repo}/contents/${path}`,
body: {message, content, sha, branch},
headers: {
'Accept': 'application/vnd.github.v3+json',
'Authorization': `token ${token}`,
'User-Agent': 'Request-Promise',
},
Expand Down

0 comments on commit 0f3b059

Please sign in to comment.