Skip to content

Commit

Permalink
Suggested PR corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
sbosio authored and k80bowman committed Jan 8, 2025
1 parent 24c57a2 commit 49d758a
Show file tree
Hide file tree
Showing 3 changed files with 5,748 additions and 6,247 deletions.
17 changes: 3 additions & 14 deletions packages/cli/src/commands/pipelines/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import HTTP from '@heroku/http-call'

import {getCoupling, getPipeline, getReleases, listPipelineApps, SDK_HEADER} from '../../lib/api'
import KolkrabbiAPI from '../../lib/pipelines/kolkrabbi-api'
import type {OciImage, Slug, Pipeline, PipelineCoupling} from '../../lib/types/fir'
import type {OciImage, Slug, PipelineCoupling} from '../../lib/types/fir'
import type {Commit, GitHubDiff} from '../../lib/types/github'

interface AppInfo {
Expand Down Expand Up @@ -46,12 +46,7 @@ async function diff(targetApp: AppInfo, downstreamApp: AppInfo, githubToken: str
Reflect.set(headers, 'user-agent', herokuUserAgent)
}

let githubDiff: GitHubDiff
try {
({body: githubDiff} = await HTTP.get<GitHubDiff>(`https://api.github.com/repos/${path}`, {headers}))
} catch {
throw new Error(`unable to perform diff for ${targetApp.name} and ${downstreamApp.name}. Are you sure you have pushed your latest commits to GitHub?`)
}
const {body: githubDiff} = await HTTP.get<GitHubDiff>(`https://api.github.com/repos/${path}`, {headers})

ux.log('')
ux.styledHeader(`${color.app(targetApp.name)} is ahead of ${color.app(downstreamApp.name)} by ${githubDiff.ahead_by} commit${githubDiff.ahead_by === 1 ? '' : 's'}`)
Expand Down Expand Up @@ -141,13 +136,7 @@ export default class PipelinesDiff extends Command {
return
}

let pipeline: Pipeline
try {
({body: pipeline} = await getPipeline(this.heroku, coupling.pipeline!.id!))
} catch {
ux.error(`Unable to fetch pipeline ${coupling.pipeline!.name}`)
return
}
const {body: pipeline} = await getPipeline(this.heroku, coupling.pipeline!.id!)

const targetAppId = coupling!.app!.id!
const generation = pipeline!.generation!.name!
Expand Down
14 changes: 5 additions & 9 deletions packages/cli/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,8 @@ export function findPipelineByName(heroku: APIClient, idOrName: string) {
})
}

export interface PipelineCouplingSdk extends Required<PipelineCoupling> {
generation: 'fir' | 'cedar'
}

export function getCoupling(heroku: APIClient, app: string) {
return heroku.get<PipelineCouplingSdk>(`/apps/${app}/pipeline-couplings`, {
return heroku.get<PipelineCoupling>(`/apps/${app}/pipeline-couplings`, {
headers: {Accept: SDK_HEADER},
})
}
Expand Down Expand Up @@ -99,24 +95,24 @@ export function getAppSetup(heroku: APIClient, buildId: any) {
}

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

export interface AppWithPipelineCoupling extends App {
pipelineCoupling: PipelineCouplingSdk
pipelineCoupling: PipelineCoupling
[k: string]: unknown
}

export async function listPipelineApps(heroku: APIClient, pipelineId: string): Promise<Array<AppWithPipelineCoupling>> {
const {body: couplings} = await listCouplings(heroku, pipelineId)
const appIds = couplings.map(coupling => coupling.app.id || '')
const appIds = couplings.map(coupling => coupling.app!.id || '')
const {body: apps} = await getAppFilter(heroku, appIds)
return apps.map(app => {
return {
...app,
pipelineCoupling: couplings.find(coupling => coupling.app.id === app.id),
pipelineCoupling: couplings.find(coupling => coupling.app!.id === app.id),
} as AppWithPipelineCoupling
})
}
Expand Down
Loading

0 comments on commit 49d758a

Please sign in to comment.