Skip to content

Commit ae69688

Browse files
authored
Merge pull request #11 from kyagi/refactoring-20220204-1
Conditional logging when run on github actions
2 parents c6115f2 + f672d46 commit ae69688

File tree

3 files changed

+22
-37
lines changed

3 files changed

+22
-37
lines changed

dist/index.js

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23670,19 +23670,6 @@ function wrappy (fn, cb) {
2367023670
/***/ 6092:
2367123671
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
2367223672

23673-
// const {Octokit} = require("@octokit/core")
23674-
// let octokit = new Octokit({auth: process.env.shamshir_pat})
23675-
//
23676-
// const core = require('@actions/core')
23677-
// const github = require('@actions/github')
23678-
// const GITHUB_TOKEN = core.getInput('GITHUB_TOKEN')
23679-
// if (!process.env.shamshir_pat) {
23680-
// octokit = github.getOctokit(GITHUB_TOKEN)
23681-
// }
23682-
// const {context = {}} = github
23683-
// const {pull_request} = context.payload
23684-
//
23685-
2368623673
const { Octokit } = __nccwpck_require__(6762)
2368723674
const core = __nccwpck_require__(2186)
2368823675
const github = __nccwpck_require__(5438)
@@ -23711,6 +23698,7 @@ module.exports = class Shamshir {
2371123698
this._quorum = core.getInput('quorum')
2371223699
this._mode = false
2371323700
} else {
23701+
// TODO: error-handing, TBD
2371423702
// Neither stand-alone nor github actions
2371523703
}
2371623704
}
@@ -23753,11 +23741,15 @@ module.exports = class Shamshir {
2375323741
level: 'error', message: `${error}`, owner: owner, repo: repo, function: 'main', mode: mode })
2375423742
} finally {
2375523743
// TODO: fix this
23756-
const fs = __nccwpck_require__(7147)
23757-
fs.readFile('combined.log', 'utf-8', (err, files) => {
23758-
if (err) { throw err; }
23759-
core.setOutput('log', files)
23760-
})
23744+
if (GITHUB_TOKEN) {
23745+
const fs = __nccwpck_require__(7147)
23746+
fs.readFile('combined.log', 'utf-8', (err, files) => {
23747+
if (err) {
23748+
throw err;
23749+
}
23750+
core.setOutput('log', files)
23751+
})
23752+
}
2376123753
logger.log({level: 'info', message: 'Shamshir finished.', owner: owner, repo: repo, mode: mode })
2376223754
}
2376323755
}

src/shamshir-stand-alone.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
const Shamshir = require("./shamshir.js")
21
const { argv } = require('./yargs.js')
32
const { owner, repo, label, quorum, check } = argv
43

54
let mode = "live"
65
if (check === true) {
76
mode = "dry-run"
87
}
8+
9+
const Shamshir = require("./shamshir.js")
910
const shamshir = new Shamshir(owner, repo, label, quorum, mode)
1011

1112
// TODO: fix or use top level await

src/shamshir.js

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
// const {Octokit} = require("@octokit/core")
2-
// let octokit = new Octokit({auth: process.env.shamshir_pat})
3-
//
4-
// const core = require('@actions/core')
5-
// const github = require('@actions/github')
6-
// const GITHUB_TOKEN = core.getInput('GITHUB_TOKEN')
7-
// if (!process.env.shamshir_pat) {
8-
// octokit = github.getOctokit(GITHUB_TOKEN)
9-
// }
10-
// const {context = {}} = github
11-
// const {pull_request} = context.payload
12-
//
13-
141
const { Octokit } = require("@octokit/core")
152
const core = require('@actions/core')
163
const github = require('@actions/github')
@@ -39,6 +26,7 @@ module.exports = class Shamshir {
3926
this._quorum = core.getInput('quorum')
4027
this._mode = false
4128
} else {
29+
// TODO: error-handing, TBD
4230
// Neither stand-alone nor github actions
4331
}
4432
}
@@ -81,11 +69,15 @@ module.exports = class Shamshir {
8169
level: 'error', message: `${error}`, owner: owner, repo: repo, function: 'main', mode: mode })
8270
} finally {
8371
// TODO: fix this
84-
const fs = require('fs')
85-
fs.readFile('combined.log', 'utf-8', (err, files) => {
86-
if (err) { throw err; }
87-
core.setOutput('log', files)
88-
})
72+
if (GITHUB_TOKEN) {
73+
const fs = require('fs')
74+
fs.readFile('combined.log', 'utf-8', (err, files) => {
75+
if (err) {
76+
throw err;
77+
}
78+
core.setOutput('log', files)
79+
})
80+
}
8981
logger.log({level: 'info', message: 'Shamshir finished.', owner: owner, repo: repo, mode: mode })
9082
}
9183
}

0 commit comments

Comments
 (0)