-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
1,211 additions
and
824 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,6 @@ | ||
#!/usr/bin/env node | ||
|
||
import { getOptions } from './options/options'; | ||
import { initSteps } from './steps/steps'; | ||
import { runWithArgs } from './runWithArgs'; | ||
const args = process.argv.slice(2); | ||
|
||
async function init() { | ||
try { | ||
const args = process.argv.slice(2); | ||
const options = await getOptions(args); | ||
return await initSteps(options); | ||
} catch (e) { | ||
if (e.name === 'HandledError') { | ||
console.error(e.message); | ||
} else { | ||
console.error(e); | ||
} | ||
|
||
process.exit(1); | ||
} | ||
} | ||
|
||
init(); | ||
runWithArgs(args); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { getOptions } from './options/options'; | ||
import { runWithOptions } from './runWithOptions'; | ||
import { HandledError } from './services/HandledError'; | ||
import { initLogger } from './services/logger'; | ||
|
||
export async function runWithArgs(args: string[]) { | ||
const logger = initLogger(); | ||
|
||
try { | ||
const options = await getOptions(args); | ||
return await runWithOptions(options); | ||
} catch (e) { | ||
if (e instanceof HandledError) { | ||
console.error(e.message); | ||
} else { | ||
console.error(e); | ||
} | ||
|
||
// wait exiting until logs have been flushed to disc | ||
logger.on('finish', () => { | ||
process.exit(1); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { BackportOptions } from './options/options'; | ||
import { verifyAccessToken } from './services/github/verifyAccessToken'; | ||
import { doBackportVersions } from './ui/doBackportVersions'; | ||
import { getBranches } from './ui/getBranches'; | ||
import { getCommits } from './ui/getCommits'; | ||
import { maybeSetupRepo } from './ui/maybeSetupRepo'; | ||
import { logger } from './services/logger'; | ||
|
||
export async function runWithOptions(options: BackportOptions) { | ||
await verifyAccessToken(options); | ||
|
||
const commits = await getCommits(options); | ||
const branches = await getBranches(options); | ||
|
||
await maybeSetupRepo(options); | ||
|
||
logger.info(`Backporting ${JSON.stringify(commits)} ${branches.join(',')}`); | ||
await doBackportVersions(options, commits, branches); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,48 @@ | ||
export function log(...args: unknown[]) { | ||
import winston, { format } from 'winston'; | ||
import yargs from 'yargs'; | ||
import isString from 'lodash.isstring'; | ||
import { getLogfilePath } from './env'; | ||
|
||
const { combine, timestamp, printf } = format; | ||
const { argv } = yargs.help(false); | ||
|
||
// wrapper around console.log | ||
export function consoleLog(...args: unknown[]) { | ||
console.log(...args); | ||
} | ||
|
||
export function error(...args: unknown[]) { | ||
console.error(...args); | ||
export let logger = ({ | ||
info: () => {}, | ||
verbose: () => {} | ||
} as unknown) as winston.Logger; | ||
|
||
export function initLogger() { | ||
logger = winston.createLogger({ | ||
transports: [ | ||
// log to file | ||
new winston.transports.File({ | ||
level: argv.verbose ? 'verbose' : 'info', | ||
format: combine( | ||
timestamp(), | ||
printf( | ||
({ level, message, timestamp }) => | ||
`${timestamp} ${level}: ${formatMessage(message)}` | ||
) | ||
), | ||
filename: getLogfilePath() | ||
}) | ||
] | ||
}); | ||
return logger; | ||
} | ||
|
||
function formatMessage(message: string | Record<any, any>) { | ||
return isString(message) ? message : JSON.stringify(message, null, 2); | ||
} | ||
|
||
// log levels: | ||
// - error | ||
// - warn | ||
// - info | ||
// - verbose | ||
// - debug |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.