Skip to content

Commit

Permalink
fix: invalid publish call to API
Browse files Browse the repository at this point in the history
  • Loading branch information
matfax committed Mar 5, 2019
1 parent f6c8de3 commit ab05be8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- '11'
- 'node'

branches:
only:
Expand All @@ -12,8 +12,7 @@ script: echo "Running tests against $(node -v) ..."
jobs:
include:
- stage: deploy
node_js: '11'
script: npm-publish-git-tag
script: yarn publish
if: tag IS present

cache:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ That circumstance impairs common maintenance and automation requirements.
| api_key | SITELEAF_API_KEY | *required* | the siteleaf API key |
| api_secret | SITELEAF_API_SECRET | *required* | the siteleaf API secret |
| site | SITE_ID | *required* | the siteleaf site id to be updated |
| page | PAGE_NAME | `index` | the siteleaf page name to be updated |
| page | PAGE_NAME | `index` | the siteleaf page path to be updated |
| file | MD_FILE | `README.md` | the name of the Markdown file to read |
| publish | - | `false` | publish the site after updating |
13 changes: 8 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const config = convict({
env: 'SITE_ID'
},
page: {
doc: 'the siteleaf page name to be updated',
doc: 'the siteleaf page path to be updated',
format: String,
default: 'index',
arg: 'page',
Expand All @@ -58,13 +58,16 @@ config.validate()

if (config.get('key') === '') error('no api key was given')
if (config.get('secret') === '') error('no api secret was given')
const auth = Buffer.from(`${config.get('key')}:${config.get('secret')}`).toString('base64')

if (config.get('site') === '') error('no site id was given')
const site = config.get('site')

const auth = Buffer.from(`${config.get('key')}:${config.get('secret')}`).toString('base64')
const findPage = unirest('GET', `https://api.siteleaf.com/v2/sites/${config.get('site')}/pages`)
const findPage = unirest('GET', `https://api.siteleaf.com/v2/sites/${site}/pages`)

findPage.query({
'q': config.get('page')
'q': config.get('page'),
'extensions': 'markdown'
})

findPage.headers({
Expand Down Expand Up @@ -101,7 +104,7 @@ findPage.end(function (res) {
if (!config.get('publish')) {
console.log(chalk.green(`Page "${res.body[0].basename}" successfully updated`))
} else {
const publishSite = unirest('GET', `https://api.siteleaf.com/v2/sites/${config.get('site')}/publish`)
const publishSite = unirest('POST', `https://api.siteleaf.com/v2/sites/${site}/publish`)

publishSite.headers({
'authorization': `Basic ${auth}`
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@
"eslint-plugin-react": "^7.12.4",
"eslint-plugin-standard": "^4.0.0",
"npm-publish-git-tag": "^3.0.3",
"siteleaf-updater": "^0.1.0",
"standard": "^12.0.1"
},
"scripts": {
"test": "node ./index.js"
"test": "node ./index.js",
"lint": "eslint --ignore-path .gitignore .",
"publish": "npm-publish-git-tag",
"postpublish": "siteleaf-updater --site 5c7e78ecaf67d949a5972c82"
},
"repository": {
"type": "git",
Expand Down
9 changes: 9 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2088,6 +2088,15 @@ signal-exit@^3.0.0, signal-exit@^3.0.2:
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
integrity sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=

siteleaf-updater@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/siteleaf-updater/-/siteleaf-updater-0.1.0.tgz#3e380be7d71d912e2760e9cbb68fd4f1e3ea0a0d"
integrity sha512-8lBOhGxzwE9DsAdHMo5hi/n/Va+lnCk59iXK9DqSg8Fl4eyCaqSIuMg8mnBtVF4H5FGt7rG3IVJgJuzDxvK31g==
dependencies:
chalk "^2.4.2"
convict "^4.4.1"
unirest "^0.6.0"

slice-ansi@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-1.0.0.tgz#044f1a49d8842ff307aad6b505ed178bd950134d"
Expand Down

0 comments on commit ab05be8

Please sign in to comment.