Skip to content

Commit

Permalink
chore(pipelines): upgrade pipelines to eslint (heroku#1405)
Browse files Browse the repository at this point in the history
  • Loading branch information
chadian authored and RasPhilCo committed Feb 3, 2020
1 parent 69d5cea commit f7b812e
Show file tree
Hide file tree
Showing 51 changed files with 1,565 additions and 1,530 deletions.
1 change: 1 addition & 0 deletions packages/pipelines/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib
9 changes: 9 additions & 0 deletions packages/pipelines/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": [
"oclif",
"oclif-typescript"
],
"rules": {
"unicorn/no-abusive-eslint-disable": "off"
}
}
9 changes: 6 additions & 3 deletions packages/pipelines/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"@oclif/dev-cli": "^1",
"@oclif/plugin-help": "^2",
"@oclif/test": "^1",
"@oclif/tslint": "^3",
"@types/chai": "^4",
"@types/got": "^9.6.7",
"@types/lodash.keyby": "^4.6.6",
Expand All @@ -31,14 +30,16 @@
"@types/node": "^10",
"chai": "^4",
"debug": "^4.1.1",
"eslint": "^6.7.2",
"eslint-config-oclif": "^3.1.0",
"eslint-config-oclif-typescript": "^0.1.0",
"globby": "^8",
"mocha": "^5",
"nock": "^10.0.6",
"nyc": "^13",
"sinon": "^7.4.1",
"ts-node": "^8",
"tslib": "^1",
"tslint": "^5",
"typescript": "3.3.3333"
},
"engines": {
Expand Down Expand Up @@ -71,10 +72,12 @@
},
"repository": "heroku/cli",
"scripts": {
"lint": "eslint . --ext .ts --config .eslintrc",
"postpack": "rm -f oclif.manifest.json",
"posttest": "tslint -p test -t stylish",
"prepack": "rm -rf lib && tsc -b && oclif-dev manifest && oclif-dev readme",
"pretest": "tsc -p test --noEmit",
"test": "nyc --extension .ts mocha \"test/**/*.test.ts\"",
"posttest": "yarn lint",
"version": "oclif-dev readme && git add README.md"
}
}
50 changes: 25 additions & 25 deletions packages/pipelines/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {APIClient} from '@heroku-cli/command'
import * as Heroku from '@heroku-cli/schema'
// tslint:disable-next-line: no-unused
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import http from 'http-call'
import keyBy from 'lodash.keyby'

Expand All @@ -12,6 +12,12 @@ export function createAppSetup(heroku: APIClient, body: {body: any}) {
return heroku.post('/app-setups', {body})
}

export function postCoupling(heroku: APIClient, pipeline: any, app: any, stage: string) {
return heroku.post('/pipeline-couplings', {
body: {app, pipeline, stage},
})
}

export function createCoupling(heroku: APIClient, pipeline: any, app: string, stage: string) {
return postCoupling(heroku, pipeline.id, app, stage)
}
Expand All @@ -20,13 +26,13 @@ export function createPipeline(heroku: APIClient, name: any, owner: any) {
return heroku.request('/pipelines', {
method: 'POST',
headers: {Accept: PIPELINES_HEADER},
body: {name, owner}
body: {name, owner},
})
}

export function createPipelineTransfer(heroku: APIClient, pipeline: Heroku.Pipeline) {
return heroku.post('/pipeline-transfers', {
body: pipeline
body: pipeline,
})
}

Expand All @@ -38,14 +44,14 @@ export function destroyPipeline(heroku: APIClient, name: any, pipelineId: any) {
return heroku.request(`/pipelines/${pipelineId}`, {
method: 'DELETE',
headers: {Accept: PIPELINES_HEADER},
body: {name}
body: {name},
})
}

export function findPipelineByName(heroku: APIClient, idOrName: string) {
return heroku.request<Heroku.Pipeline[]>(`/pipelines?eq[name]=${idOrName}`, {
method: 'GET',
headers: {Accept: PIPELINES_HEADER}
headers: {Accept: PIPELINES_HEADER},
})
}

Expand All @@ -56,13 +62,13 @@ export function getCoupling(heroku: APIClient, app: string) {
export function getPipeline(heroku: APIClient, id: string) {
return heroku.request<Heroku.Pipeline>(`/pipelines/${id}`, {
method: 'GET',
headers: {Accept: PIPELINES_HEADER}
headers: {Accept: PIPELINES_HEADER},
})
}

export function updatePipeline(heroku: APIClient, id: string, body: Heroku.Pipeline) {
return heroku.patch<Heroku.Pipeline>(`/pipelines/${id}`, {
body
body,
})
}

Expand All @@ -78,7 +84,7 @@ function getAppFilter(heroku: APIClient, appIds: Array<string>) {
return heroku.request<Array<Heroku.App>>('/filters/apps', {
method: 'POST',
headers: {Accept: FILTERS_HEADER},
body: {in: {id: appIds}}
body: {in: {id: appIds}},
})
}

Expand All @@ -90,51 +96,45 @@ export function getAppSetup(heroku: APIClient, buildId: any) {
return heroku.get(`/app-setups/${buildId}`)
}

function listCouplings(heroku: APIClient, pipelineId: string) {
return heroku.get<Array<Heroku.PipelineCoupling>>(`/pipelines/${pipelineId}/pipeline-couplings`)
}

export function listPipelineApps(heroku: APIClient, pipelineId: string): Promise<Array<Heroku.App>> {
return listCouplings(heroku, pipelineId).then(({body: couplings}) => {
const appIds = couplings.map(coupling => coupling.app && coupling.app.id || '')
const appIds = couplings.map(coupling => (coupling.app && coupling.app.id) || '')

return getAppFilter(heroku, appIds).then(({body: apps}) => {
const couplingsByAppId = keyBy(couplings, coupling => coupling.app && coupling.app.id)
return apps.map(app => {
return {
...app,
coupling: couplingsByAppId[app.id!]
coupling: couplingsByAppId[app.id!],
}
})
})
})
}

function listCouplings(heroku: APIClient, pipelineId: string) {
return heroku.get<Array<Heroku.PipelineCoupling>>(`/pipelines/${pipelineId}/pipeline-couplings`)
}

export function patchCoupling(heroku: APIClient, id: string, stage: string) {
return heroku.patch(`/pipeline-couplings/${id}`, {body: {stage}})
}

export function postCoupling(heroku: APIClient, pipeline: any, app: any, stage: string) {
return heroku.post('/pipeline-couplings', {
body: {app, pipeline, stage}
})
}

export function removeCoupling(heroku: APIClient, app: string) {
return getCoupling(heroku, app)
.then(({body}) => {
return deleteCoupling(heroku, body.id!)
})
.then(({body}) => {
return deleteCoupling(heroku, body.id!)
})
}

export function updateCoupling(heroku: APIClient, app: string, stage: string) {
return getCoupling(heroku, app)
.then(({body: coupling}) => patchCoupling(heroku, coupling.id!, stage))
.then(({body: coupling}) => patchCoupling(heroku, coupling.id!, stage))
}

export function getReleases(heroku: APIClient, appId: string) {
return heroku.get<Array<Heroku.Release>>(`/apps/${appId}/releases`, {
headers: {Accept: V3_HEADER, Range: 'version ..; order=desc'},
partial: true
partial: true,
})
}
18 changes: 9 additions & 9 deletions packages/pipelines/src/commands/pipelines/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The app and pipeline names must be specified.
The stage of the app will be guessed based on its name if not specified.`

static examples = [
'$ heroku pipelines:add my-pipeline -a my-app -s production'
'$ heroku pipelines:add my-pipeline -a my-app -s production',
]

static flags = {
Expand All @@ -24,25 +24,25 @@ The stage of the app will be guessed based on its name if not specified.`
stage: flags.string({
char: 's',
description: 'stage of first app in pipeline',
completion: StageCompletion
})
completion: StageCompletion,
}),
}

static args = [{
name: 'pipeline',
description: 'name of pipeline',
required: true
required: true,
}]

async run() {
const {args, flags} = this.parse(PipelinesAdd)
const app = flags.app

let stage
let guesses = infer(app)
let questions = []
const guesses = infer(app)
const questions = []

let pipeline: any = await disambiguate(this.heroku, args.pipeline)
const pipeline: any = await disambiguate(this.heroku, args.pipeline)

if (flags.stage) {
stage = flags.stage
Expand All @@ -52,11 +52,11 @@ The stage of the app will be guessed based on its name if not specified.`
name: 'stage',
message: `Stage of ${app}`,
choices: stageNames,
default: guesses[1]
default: guesses[1],
})
}

let answers: any = await prompt(questions)
const answers: any = await prompt(questions)
if (answers.stage) stage = answers.stage

cli.action.start(`Adding ${color.app(app)} to ${color.pipeline(pipeline.name)} pipeline as ${stage}`)
Expand Down
19 changes: 10 additions & 9 deletions packages/pipelines/src/commands/pipelines/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ export default class Connect extends Command {
static description = 'connect a github repo to an existing pipeline'

static examples = [
'$ heroku pipelines:connect my-pipeline -r githuborg/reponame'
'$ heroku pipelines:connect my-pipeline -r githuborg/reponame',
]

static flags = {
repo: flags.string({
name: 'repo',
char: 'r',
description: 'the GitHub repository to connect to',
required: true
})
required: true,
}),
}

static args = [{
name: 'name',
description: 'name of pipeline',
Expand All @@ -33,14 +34,14 @@ export default class Connect extends Command {
async run() {
const {args, flags} = this.parse(Connect)

let combinedInputs = {
const combinedInputs = {
name: args.name,
repo: flags.repo
repo: flags.repo,
}

const errors = nameAndRepo({repo: flags.repo})

if (errors.length) {
if (errors.length !== 0) {
this.error(errors.join(', '))
return
}
Expand All @@ -49,9 +50,9 @@ export default class Connect extends Command {
const github = new GitHubAPI(this.config.userAgent, await getGitHubToken(kolkrabbi))

const {
name: pipelineName,
repo: repoName
} = await getNameAndRepo(combinedInputs)
name: pipelineName,
repo: repoName,
} = await getNameAndRepo(combinedInputs)

const repo = await getRepo(github, repoName)

Expand Down
28 changes: 13 additions & 15 deletions packages/pipelines/src/commands/pipelines/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class Create extends Command {

static examples = [
'$ heroku pipelines:create -a my-app-staging',
'$ heroku pipelines:create my-pipeline -a my-app-staging'
'$ heroku pipelines:create my-pipeline -a my-app-staging',
]

static flags = {
Expand All @@ -27,17 +27,17 @@ export default class Create extends Command {
name: 'stage',
char: 's',
description: 'stage of first app in pipeline',
completion: StageCompletion
completion: StageCompletion,
}),
team: flags.team({
description: 'the team which will own the apps'
})
description: 'the team which will own the apps',
}),
}

static args = [{
name: 'name',
description: 'name of pipeline (defaults to basename of the app)',
required: false
required: false,
}]

async run() {
Expand All @@ -46,10 +46,8 @@ export default class Create extends Command {
let name
let stage
let owner: any
let ownerID
let ownerType
let guesses = infer(flags.app)
let questions: any = []
const guesses = infer(flags.app)
const questions: any = []

const app = flags.app

Expand All @@ -60,7 +58,7 @@ export default class Create extends Command {
type: 'input',
name: 'name',
message: 'Pipeline name',
default: guesses[0]
default: guesses[0],
})
}
if (flags.stage) {
Expand All @@ -71,26 +69,26 @@ export default class Create extends Command {
name: 'stage',
message: `Stage of ${app}`,
choices: stages,
default: guesses[1]
default: guesses[1],
})
}

const teamName = flags.team
ownerType = teamName ? 'team' : 'user'
const ownerType = teamName ? 'team' : 'user'

// If team or org is not specified, we assign ownership to the user creating
owner = teamName ? await getTeam(this.heroku, teamName) : await getAccountInfo(this.heroku)
owner = owner.body
ownerID = owner.id
const ownerID = owner.id

owner = {id: ownerID, type: ownerType}

let answers: any = await prompt(questions)
const answers: any = await prompt(questions)
if (answers.name) name = answers.name
if (answers.stage) stage = answers.stage

cli.action.start(`Creating ${name} pipeline`)
let {body: pipeline}: any = await createPipeline(this.heroku, name, owner)
const {body: pipeline}: any = await createPipeline(this.heroku, name, owner)
cli.action.stop()

cli.action.start(`Adding ${color.app(app)} to ${color.pipeline(pipeline.name)} pipeline as ${stage}`)
Expand Down
Loading

0 comments on commit f7b812e

Please sign in to comment.