Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"semi": false,
"printWidth": 100,
"rules":
"rules": {

}
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.4.0

- `devOps` and `cli` namespaces.

## 0.3.0

- Avocado can detect Azure Dev Ops PR validation and show only relevant errors.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure/avocado",
"version": "0.3.3",
"version": "0.4.0",
"description": "A validator of OpenAPI configurations",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -68,15 +68,15 @@
"devDependencies": {
"@types/mocha": "^5.2.6",
"@types/node": "^11.10.4",
"mocha": "^6.0.2",
"mocha-junit-reporter": "^1.21.0",
"mocha": "^6.1.4",
"mocha-junit-reporter": "^1.22.0",
"mocha-multi-reporters": "^1.1.7",
"nyc": "^13.3.0",
"prettier": "^1.16.4",
"tslint": "^5.15.0",
"nyc": "^14.0.0",
"prettier": "^1.17.0",
"tslint": "^5.16.0",
"tslint-config-prettier": "^1.18.0",
"tslint-immutable": "^5.5.2",
"tslint-plugin-prettier": "^2.0.1",
"typescript": "^3.4.2"
"typescript": "^3.4.3"
}
}
29 changes: 25 additions & 4 deletions src/dev-ops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,30 @@ import * as git from "./git"
import * as path from "path"
import * as fs from "@ts-common/fs"

export type FileChangeKind = 'Added'|'Deleted'|'Modified'
export type FileChangeKind = "Added" | "Deleted" | "Modified"

export type FileChange = {
readonly kind: FileChangeKind
readonly path: string
}

/**
* Properties of Pull Request in Azure DevOps CI.
*/
export type PullRequestProperties = {
// Target Branch, for example `master`.
readonly targetBranch: string

// Source Branch, for example `myname/newchanges`.
readonly sourceBranch: string

// Working folder for a cloned directory. We can't switch branches in the original Git repository so we use cloned repository.
readonly workingDir: string

// Checkout Git branch, for example, it can be `targetBranch` or `sourceBranch`.
readonly checkout: (branch: string) => Promise<void>

// The method returns a set of changes between `targetBranch` and `sourceBranch`.
// tslint:disable-next-line:prettier
readonly diff: () => Promise<readonly FileChange[]>
}
Expand All @@ -23,13 +35,22 @@ const sourceBranch = "source-b6791c5f-e0a5-49b1-9175-d7fd3e341cb8"

const parseGitFileChangeKind = (line: string) => {
switch (line[0]) {
case "A": return "Added"
case "D": return "Deleted"
default: return "Modified"
case "A":
return "Added"
case "D":
return "Deleted"
default:
return "Modified"
}
}

/**
* If the function is called in Azure DevOps CI for a Pull Request, it creates a
* clone of the Git repository and returns properties of the Pull Request, such as
* `targetBranch` and `sourceBranch`.
*
* The function returns `undefined` if it's not Azure DevOps CI for a Pull Request.
*
* Currently, the algorithm is recognizing Azure Dev Ops Pull Request if the `env` has
* `SYSTEM_PULLREQUEST_TARGETBRANCH`. `cwd` should point to the source Git repository.
*/
Expand Down
3 changes: 1 addition & 2 deletions src/git.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// tslint:disable:prettier
import * as util from "util"
import * as childProcess from "child_process"
import * as stringMap from "@ts-common/string-map"
Expand All @@ -9,11 +10,9 @@ export type ExecResult = {
readonly stderr: string
}

// tslint:disable-next-line:prettier
export type GenericCommand = stringMap.StringMap<readonly string[]>

export type Command =
// tslint:disable-next-line:prettier
{ readonly config: readonly ["user.email" | "user.name", string] } |
{ readonly init: readonly [] } |
{ readonly add: readonly [string] } |
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import * as cli from "./cli"
import nodeObjectHash = require("node-object-hash")
import * as devOps from "./dev-ops"

export { createPullRequestProperties, PullRequestProperties } from "./dev-ops"
export { defaultConfig, Config } from "./cli"
export { devOps, cli }

export type JsonParseError = {
readonly code: "JSON_PARSE"
Expand Down