Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let data: any = []
latestTestRuns.forEach(testRun => {
data.push(
{
iconStatus: `${statusIcon(testRun)}`,
number: testRun.number,
branch: testRun.commit_branch,
sha: testRun.commit_sha!.slice(0, 7),
status: testRun.status
}
)
})
cli.table(data, {
printHeader: undefined,
columns: [
{key: 'iconStatus', width: 1, label: ''}, // label '' is to make sure that widh is 1 character
{key: 'number', label: ''},
{key: 'branch'},
{key: 'sha'},
{key: 'status'}
]
})
if (watchOption) {
process.stdout.write(ansiEscapes.cursorUp(latestTestRuns.length))
}
}
// Transforms string arrays to arrays
const parsedInputs = parseArrayInputs(inputs)
// Intialize ethers contract factory
const factory = new ethers.ContractFactory(
abi['compilerOutput']['abi'],
abi['compilerOutput']['evm']['bytecode'],
wallet,
)
// Deploy contract
let contract: ethers.Contract
try {
contract = await factory.deploy(...parsedInputs, overrides)
cli.action.start(
`Deploying ${versionedContractName} to ${contract.address} `,
)
// TODO: add numConfirmations to .beltrc
const receipt = await contract.deployTransaction.wait(1) // wait for 1 confirmation
cli.action.stop(`Deployed in tx ${receipt.transactionHash}`)
return contract.address
} catch (e) {
this.error(chalk.red(e))
}
return
}
])
try {
this.newLine()
cli.action.start('Authenticating at Harvest')
// check if we have authorization using the provided credentials.
const user = await getClient(access).users.me()
cli.action.stop('ok!')
this.log(chalk.bold(`Hello, ${user.first_name}! You are connected ;)`))
saveConfig({ access, user })
} catch (err) /* istanbul ignore next */ {
cli.action.stop('outch!')
if (err.statusCode !== 401 || !err.error) {
this.error(err.message)
this.exit(1)
}
this.warn(
chalk.bold(JSON.parse(err.error).error_description),
'Please, try again:'
)
// try again.
return this.configure()
}
return getConfig()
let user: { username: string, password: string } = { username: '', password: '' };
const question = {
name: 'way',
message: 'There are two ways you can login:',
type: 'list',
choices: [{ name: 'Login by Username & Password' }, { name: 'Login by Browser' }]
};
const maxRepeat: number = 30; // for login with browser
const waitTime: number = 5000; // for login with browser
const code = makeId(); // for login with browser
const answer: { way: string } = await inquirer.prompt([question]);
if (answer.way === question.choices[0].name) { // login with username & password
user.username = await cli.prompt(messages.username_req, { required: true });
user.password = await cli.prompt(messages.password_req, { required: true, type: 'hide' });
try {
let data = (await authService.login(user)).data; // sends user credentials to the server
await writeToken(this, { token: data.result }); // write the access token in the file
let value = await authService.overview(this); // sends request the get the user's config
let overview = JSON.stringify(value.data.result);
await writeOverview(this, overview) // write the user's config to the file
console.log(color.green(messages.loggedin));
}
catch (e) {
common.logError(e);
}
}
else { // login with browser
try {
await opn(`${auth_url}${code}`, { wait: false });
const code = request.query.code;
const token = await this.fetchToken(code);
resolve(token.access_token);
return 'Thank you. You can close this tab.';
} catch (err) {
reject(err);
} finally {
this.server.stop();
}
},
});
const codeChallenge = this.base64url(createHash('sha256').update(this.codeVerifier).digest('base64'));
const authorizeUrl = this.buildAuthorizeUrl(codeChallenge);
cli.log(chalk.green('*') + ' ' + chalk.white('...if your browser does not open, open this:')
+ ' ' + chalk.underline(chalk.blue(authorizeUrl)));
open(authorizeUrl);
this.server.start();
} catch (e) {
// tslint:disable-next-line:no-console
console.log('Error inside of the execute:', e);
}
});
}
// Make sure that we have an Auth0 client id
const clientId = config.get('auth0.hereditasClientId')
if (!clientId) {
this.error('The Hereditas application hasn\'t been configured on Auth0 yet. Please run `hereditas auth0:sync` first')
return this.exit(1)
}
// Check if we have a passphrase passed as environmental variable (useful for development only)
let passphrase
if (process.env.HEREDITAS_PASSPHRASE) {
passphrase = process.env.HEREDITAS_PASSPHRASE
this.warn('Passphrase set through the HEREDITAS_PASSPHRASE environmental variable; this should be used for development only')
}
else {
// Ask for the user passphrase
passphrase = await cli.prompt('User passphrase', {type: 'mask'})
}
if (!passphrase || passphrase.length < 8) {
this.error('Passphrase needs to be at least 8 characters long')
return this.exit(1)
}
// Timer
const startTime = Date.now()
// Build the project
const builder = new Builder(passphrase, config)
await builder.build()
// Done!
const duration = (Date.now() - startTime) / 1000
async run () {
const {
flags: { 'per-page': per_page, page, ...options }
} = this.parse(LogListCommand)
cli.action.start('Loading your time entries')
const { time_entries } = await this.loadTimeEntries({ per_page, page })
cli.action.stop('here they are!')
this.newLine()
/* istanbul ignore next */
cli.table(
time_entries,
{
id: {},
date: { get: ({ created_at }) => created_at },
client: { get: ({ client: { name } }) => name },
project: { get: ({ project: { name } }) => name },
task: { get: ({ task: { name } }) => name },
hours: {},
status: {
get: ({ is_running }) => (is_running ? 'Running' : 'Finished')
}
},
options
)
// console.log(JSON.stringify(time_entries, null, 2))
const githubDiff: any = await HTTP.get(`https://api.github.com/repos/${path}`, {
headers,
}).then(res => res.body)
cli.log('')
cli.styledHeader(`${color.app(targetApp.name)} is ahead of ${color.app(downstreamApp.name)} by ${githubDiff.ahead_by} commit${githubDiff.ahead_by === 1 ? '' : 's'}`)
const mapped = githubDiff.commits.map((commit: any) => {
return {
sha: commit.sha.substring(0, 7),
date: commit.commit.author.date,
author: commit.commit.author.name,
message: commit.commit.message.split('\n')[0],
}
}).reverse()
cli.table(mapped, {
sha: {
header: 'SHA',
},
date: {},
author: {},
message: {},
})
cli.log(`\nhttps://github.com/${path}`)
// tslint:disable-next-line: no-unused
} catch (error) {
cli.log(`\n${color.app(targetApp.name)} was not compared to ${color.app(downstreamApp.name)} because we were unable to perform a diff`)
cli.log('are you sure you have pushed your latest commits to GitHub?')
}
}
// Do the actual Github diff
try {
const path = `${targetApp.repo}/compare/${downstreamApp.hash}...${targetApp.hash}`
const headers: { authorization: string; 'user-agent'?: string} = {authorization: 'token ' + githubToken}
if (herokuUserAgent) {
headers['user-agent'] = herokuUserAgent
}
const githubDiff: any = await HTTP.get(`https://api.github.com/repos/${path}`, {
headers,
}).then(res => res.body)
cli.log('')
cli.styledHeader(`${color.app(targetApp.name)} is ahead of ${color.app(downstreamApp.name)} by ${githubDiff.ahead_by} commit${githubDiff.ahead_by === 1 ? '' : 's'}`)
const mapped = githubDiff.commits.map((commit: any) => {
return {
sha: commit.sha.substring(0, 7),
date: commit.commit.author.date,
author: commit.commit.author.name,
message: commit.commit.message.split('\n')[0],
}
}).reverse()
cli.table(mapped, {
sha: {
header: 'SHA',
},
date: {},
author: {},
message: {},
})
if (onLatest.length === relevantDynos.length) {
if (!released) {
cli.action.stop(`${releasedFraction}, done`)
}
break
}
if (released) {
released = false
cli.action.start(`Waiting for every dyno to be running v${latestRelease.version}`)
}
cli.action.status = releasedFraction
// eslint-disable-next-line no-await-in-loop
await cli.wait(interval * 1000)
}
}
}