Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure Devops support #1016

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .npmrc
@@ -0,0 +1,2 @@
@ffuf:registry=https://pkgs.dev.azure.com/ffuf/FFUF-Packages/_packaging/angular/npm/registry/
always-auth=true
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -15,6 +15,8 @@ x

<!-- Your comment below this -->

- Azure DevOps support - [@jonasbark], [@devandanger]

<!-- Your comment above this -->

# 9.3.0
Expand Down
12,862 changes: 12,862 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "danger",
"version": "9.3.0",
"name": "@ffuf/danger",
"version": "9.3.1",
"description": "Unit tests for Team Culture",
"main": "distribution/danger.js",
"typings": "distribution/danger.d.ts",
Expand Down Expand Up @@ -58,7 +58,7 @@
"test:watch": "jest --watch",
"lint": "tslint \"source/**/*.ts\"",
"lint:fix": "tslint \"source/**/*.ts\" --fix",
"prepublishOnly": "yarn build && yarn jest && yarn declarations && yarn build:flow-types && yarn build:pretty-types",
"prepublishOnly": "yarn build && yarn declarations && yarn build:flow-types && yarn build:pretty-types",
"build": "shx rm -rf ./distribution && tsc -p tsconfig.production.json && madge ./distribution --circular",
"build:fast": "tsc -p tsconfig.production.json",
"build:flow-types": "cp source/danger.d.ts source/_danger.d.ts && sed -ie 's/api: GitHub/api: any/g' source/_danger.d.ts && npx flowgen@1.3.0 source/_danger.d.ts -o distribution/danger.js.flow && node scripts/update_flow_types.js",
Expand Down
31 changes: 31 additions & 0 deletions source/ci_source/providers/AzureDevops.ts
@@ -0,0 +1,31 @@
import { Env, CISource } from "../ci_source"
import { ensureEnvKeysExist } from "../ci_source_helpers"

export class AzureDevops implements CISource {
constructor(private readonly env: Env) {}
get name(): string {
return "AzureDevops"
}

get isCI(): boolean {
return true
}
get isPR(): boolean {
return ensureEnvKeysExist(this.env, ["SYSTEM_PULLREQUEST_PULLREQUESTID", "SYSTEM_PULLREQUEST_PULLREQUESTNUMBER"])
}
get repoSlug(): string {
return this.env.BUILD_REPOSITORY_NAME
}
get pullRequestID(): string {
return this.env.SYSTEM_PULLREQUEST_PULLREQUESTID
}
get commitHash(): string {
return this.env.SYSTEM_PULLREQUEST_SOURCECOMMITID
}
get ciRunURL(): string {
return this.env.SYSTEM_PULLREQUEST_PULLREQUESTID
}
get useEventDSL(): boolean {
return false
}
}
5 changes: 4 additions & 1 deletion source/ci_source/providers/index.ts
Expand Up @@ -24,6 +24,7 @@ import { Travis } from "./Travis"
import { VSTS } from "./VSTS"
import { BitbucketPipelines } from "./BitbucketPipelines"
import { Cirrus } from "./Cirrus"
import { AzureDevops } from "./AzureDevops"

const providers = [
FakeCI,
Expand Down Expand Up @@ -52,6 +53,7 @@ const providers = [
AppCenter,
BitbucketPipelines,
Cirrus,
AzureDevops,
]

// Mainly used for Dangerfile linting
Expand All @@ -78,7 +80,8 @@ const realProviders = [
CodeBuild,
Codefresh,
AppCenter,
Cirrus
Cirrus,
AzureDevops,
]

export { providers, realProviders }
1 change: 1 addition & 0 deletions source/commands/danger.ts
Expand Up @@ -4,6 +4,7 @@ import program from "commander"
import chalk from "chalk"
import { version } from "../../package.json"

// @ts-ignore
process.on("unhandledRejection", function(reason: string, _p: any) {
console.log(chalk.red("Error: "), reason)
process.exitCode = 1
Expand Down
1 change: 1 addition & 0 deletions source/commands/utils/sharedDangerfileArgs.ts
@@ -1,6 +1,7 @@
import program from "commander"
import chalk from "chalk"

// @ts-ignore
process.on("unhandledRejection", function(reason: string, _p: any) {
console.log(chalk.red("Error: "), reason)
process.exitCode = 1
Expand Down
34 changes: 33 additions & 1 deletion source/danger.d.ts
Expand Up @@ -1647,6 +1647,36 @@ interface GitLabMRCommit {
committer_email: string
committed_date: string
}

interface GitLabRepositoryFile {
file_name: string
file_path: string
size: number
encoding: "base64"
content: string
content_sha256: string
ref: string
blob_id: string
commit_id: string
last_commit_id: string
}

interface GitLabCommit {
id: string
short_id: string
title: string
author_name: string
author_email: string
created_at: string
}

interface GitLabRepositoryCompare {
commit: GitLabCommit
commits: GitLabCommit[]
diffs: GitLabMRChange[]
compare_timeout: boolean
compare_same_ref: boolean
}
/**
* The result of user doing warn, message or fail, built this way for
* expansion later.
Expand Down Expand Up @@ -1681,6 +1711,8 @@ interface CliArgs {
dangerfile: string
/** So you can have many danger runs in one code review */
id: string
/** Use staged changes */
staging?: boolean
}

// NOTE: if add something new here, you need to change dslGenerator.ts
Expand Down Expand Up @@ -1735,7 +1767,7 @@ declare function message(message: MarkdownString, file?: string, line?: number):
/**
* Adds a message to the Danger table, the only difference between this
* and warn is the default emoji which shows in the table.
* You can also specify a custom emoji to show in the table for each message
* You can also specifiy a custom emoji to show in the table for each message
*
* @param {MarkdownString} message the String to output
* @param {{file?: string, line?: string, icon?: MarkdownString}} [opts]
Expand Down
11 changes: 2 additions & 9 deletions source/debug.ts
@@ -1,11 +1,4 @@
import debugModule from "debug"

export const debug = (value: string) => {
const d = debugModule(`danger:${value}`)
// In Peril, when running inside Hyper, we don't get access to stderr
// so bind debug to use stdout
if (process.env.x_hyper_content_sha256) {
d.log = console.log.bind(console)
}
return d
console.log(value)
return console.log
}
7 changes: 2 additions & 5 deletions source/runner/Executor.ts
Expand Up @@ -40,6 +40,7 @@ import { DangerRunner } from "./runners/runner"
import { GitDSL } from "../dsl/GitDSL"
import { DangerDSL } from "../dsl/DangerDSL"
import { emptyGitJSON } from "../platforms/github/GitHubGit"
import Process = NodeJS.Process

export interface ExecutorOptions {
/** Should we do a text-only run? E.g. skipping comments */
Expand All @@ -63,10 +64,6 @@ export interface ExecutorOptions {

const isTests = typeof jest === "object"

interface ExitCodeContainer {
exitCode: number
}

export class Executor {
private readonly d = debug("executor")
private readonly log = isTests ? () => "" : console.log
Expand All @@ -77,7 +74,7 @@ export class Executor {
public readonly platform: Platform,
public readonly runner: DangerRunner,
public readonly options: ExecutorOptions,
public readonly process: ExitCodeContainer
public readonly process: Process
) {}

/**
Expand Down