diff --git a/.prettierrc b/.prettierrc index df7e68f4..13eb4006 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,5 +1,7 @@ { "semi": false, "printWidth": 100, - "rules": + "rules": { + + } } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ee68ac3..08be91ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. \ No newline at end of file diff --git a/package.json b/package.json index bfddf67e..b5bffbd0 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" } } diff --git a/src/dev-ops.ts b/src/dev-ops.ts index 20f81c59..25bf44a6 100644 --- a/src/dev-ops.ts +++ b/src/dev-ops.ts @@ -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 + + // The method returns a set of changes between `targetBranch` and `sourceBranch`. // tslint:disable-next-line:prettier readonly diff: () => Promise } @@ -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. */ diff --git a/src/git.ts b/src/git.ts index a6dfaad3..05e218a0 100644 --- a/src/git.ts +++ b/src/git.ts @@ -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" @@ -9,11 +10,9 @@ export type ExecResult = { readonly stderr: string } -// tslint:disable-next-line:prettier export type GenericCommand = stringMap.StringMap export type Command = - // tslint:disable-next-line:prettier { readonly config: readonly ["user.email" | "user.name", string] } | { readonly init: readonly [] } | { readonly add: readonly [string] } | diff --git a/src/index.ts b/src/index.ts index d0114200..c2502425 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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"