-
-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style(providers): update type definition for ci providers
- Loading branch information
Showing
7 changed files
with
163 additions
and
54 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Env, CISource } from '../ci_source'; | ||
import { ensureEnvKeysExist, ensureEnvKeysAreInt } from '../ci_source_helpers'; | ||
|
||
export class Circle implements CISource { | ||
constructor(private readonly env: Env) { | ||
} | ||
|
||
get name(): string { return 'Circle CI'; } | ||
|
||
get isCI(): boolean { | ||
return ensureEnvKeysExist(this.env, ['CIRCLE_BUILD_NUM']); | ||
} | ||
|
||
get isPR(): boolean { | ||
if (ensureEnvKeysExist(this.env, ['CI_PULL_REQUEST'])) { | ||
return true; | ||
} | ||
|
||
const mustHave = ['CIRCLE_CI_API_TOKEN', 'CIRCLE_PROJECT_USERNAME', 'CIRCLE_PROJECT_REPONAME', 'CIRCLE_BUILD_NUM']; | ||
return ensureEnvKeysExist(this.env, mustHave) && ensureEnvKeysAreInt(this.env, ['CIRCLE_PR_NUMBER']); | ||
} | ||
|
||
private _prParseURL(): {owner?: string, reponame?: string, id?: string} { | ||
const prUrl = this.env.CI_PULL_REQUEST || ''; | ||
const splitSlug = prUrl.split('/'); | ||
if (splitSlug.length === 7) { | ||
const owner = splitSlug[3]; | ||
const reponame = splitSlug[4]; | ||
const id = splitSlug[6]; | ||
return {owner, reponame, id}; | ||
}; | ||
return {}; | ||
} | ||
|
||
get pullRequestID(): string { | ||
if (this.env.CIRCLE_PR_NUMBER) { | ||
return this.env.CIRCLE_PR_NUMBER; | ||
} else { | ||
const {id} = this._prParseURL(); | ||
return id || ''; | ||
} | ||
} | ||
|
||
get repoSlug(): string { | ||
const {owner, reponame} = this._prParseURL(); | ||
return (owner && reponame) ? `${owner}/${reponame}` : ''; | ||
} | ||
|
||
get repoURL(): string { return this.env.CIRCLE_REPOSITORY_URL; } | ||
get supportedPlatforms(): string[] { return ['github']; } | ||
} |
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,23 @@ | ||
import { Env, CISource } from '../ci_source'; | ||
import { ensureEnvKeysExist } from '../ci_source_helpers'; | ||
|
||
export class FakeCI implements CISource { | ||
private readonly env: Env; | ||
|
||
constructor(env: Env) { | ||
const defaults = { | ||
repo: env.DANGER_TEST_REPO || 'artsy/emission', | ||
pr: env.DANGER_TEST_PR || '327' | ||
}; | ||
|
||
this.env = {...env, ...defaults}; | ||
} | ||
get name(): string { return 'Fake Testing CI'; } | ||
|
||
get isCI(): boolean { return ensureEnvKeysExist(this.env, ['DANGER_FAKE_CI']); } | ||
get isPR(): boolean { return true; } | ||
|
||
get pullRequestID(): string { return this.env.pr; } | ||
get repoSlug(): string { return this.env.repo; } | ||
get supportedPlatforms(): Array<string> { return ['github']; } | ||
} |
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,33 @@ | ||
import { Env, CISource } from '../ci_source'; | ||
import { ensureEnvKeysExist, ensureEnvKeysAreInt } from '../ci_source_helpers'; | ||
|
||
export class Jenkins implements CISource { | ||
constructor(private readonly env: Env) { | ||
} | ||
|
||
get name(): string { | ||
return 'Jenkins'; | ||
} | ||
|
||
get isCI(): boolean { | ||
return ensureEnvKeysExist(this.env, ['JENKINS_URL']); | ||
} | ||
|
||
get isPR(): boolean { | ||
const mustHave = ['JENKINS_URL', 'ghprbPullId', 'ghprbGhRepository']; | ||
const mustBeInts = ['ghprbPullId']; | ||
return ensureEnvKeysExist(this.env, mustHave) && ensureEnvKeysAreInt(this.env, mustBeInts); | ||
} | ||
|
||
get pullRequestID(): string { | ||
return this.env.ghprbPullId; | ||
} | ||
|
||
get repoSlug(): string { | ||
return this.env.ghprbGhRepository; | ||
} | ||
|
||
get supportedPlatforms(): Array<string> { | ||
return ['github']; | ||
} | ||
} |
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,23 @@ | ||
import { Env, CISource } from '../ci_source'; | ||
import { ensureEnvKeysExist, ensureEnvKeysAreInt } from '../ci_source_helpers'; | ||
|
||
export class Semaphore implements CISource { | ||
constructor(private readonly env: Env) { | ||
} | ||
|
||
get name(): string { return 'Travis CI'; } | ||
|
||
get isCI(): boolean { | ||
return ensureEnvKeysExist(this.env, ['SEMAPHORE']); | ||
} | ||
|
||
get isPR(): boolean { | ||
const mustHave = ['SEMAPHORE_REPO_SLUG']; | ||
const mustBeInts = ['PULL_REQUEST_NUMBER']; | ||
return ensureEnvKeysExist(this.env, mustHave) && ensureEnvKeysAreInt(this.env, mustBeInts); | ||
} | ||
|
||
get pullRequestID(): string { return this.env.PULL_REQUEST_NUMBER; } | ||
get repoSlug(): string { return this.env.SEMAPHORE_REPO_SLUG; } | ||
get supportedPlatforms(): string[] { return ['github']; } | ||
} |
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,23 @@ | ||
import { Env, CISource } from '../ci_source'; | ||
import { ensureEnvKeysExist, ensureEnvKeysAreInt } from '../ci_source_helpers'; | ||
|
||
export class Travis implements CISource { | ||
constructor(private readonly env: Env) { | ||
} | ||
|
||
get name(): string { return 'Travis CI'; } | ||
|
||
get isCI(): boolean { | ||
return ensureEnvKeysExist(this.env, ['HAS_JOSH_K_SEAL_OF_APPROVAL']); | ||
} | ||
|
||
get isPR(): boolean { | ||
const mustHave = ['HAS_JOSH_K_SEAL_OF_APPROVAL', 'TRAVIS_PULL_REQUEST', 'TRAVIS_REPO_SLUG']; | ||
const mustBeInts = ['TRAVIS_PULL_REQUEST']; | ||
return ensureEnvKeysExist(this.env, mustHave) && ensureEnvKeysAreInt(this.env, mustBeInts); | ||
} | ||
|
||
get pullRequestID(): string { return this.env.TRAVIS_PULL_REQUEST; } | ||
get repoSlug(): string { return this.env.TRAVIS_REPO_SLUG; } | ||
get supportedPlatforms(): string[] { return ['github']; } | ||
} |
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,10 @@ | ||
import {Travis} from './Travis'; | ||
import {Circle} from './Circle'; | ||
import {Semaphore} from './Semaphore'; | ||
import {Jenkins} from './Jenkins'; | ||
import {FakeCI} from './Fake'; | ||
|
||
const providers: Array<any> = [Travis, Circle, Semaphore, Jenkins, FakeCI]; | ||
export { | ||
providers | ||
}; |