Skip to content

Commit be95c4d

Browse files
kimsey0Danny McCormick
authored andcommitted
Cleanup strings in samples (#280)
* Normalize quotes in samples to double quotes. * Use template strings where applicable in samples. * Normalize quotes in README to double quotes.
1 parent e852eb9 commit be95c4d

13 files changed

Lines changed: 186 additions & 186 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ npm install azure-devops-node-api --save
2626

2727
### Create a connection
2828
```javascript
29-
import * as azdev from 'azure-devops-node-api';
29+
import * as azdev from "azure-devops-node-api";
3030

3131
// your collection url
3232
let orgUrl = "https://dev.azure.com/yourorgname";
@@ -41,7 +41,7 @@ let connection = new azdev.WebApi(orgUrl, authHandler);
4141
### Get an instance of a client
4242

4343
```javascript
44-
import * as ba from 'azure-devops-node-api/BuildApi';
44+
import * as ba from "azure-devops-node-api/BuildApi";
4545

4646
let build: ba.IBuildApi = await connection.getBuildApi();
4747
```
@@ -79,10 +79,10 @@ These clients are available:
7979
Coding is easy using linear coding with async/await in TypeScript
8080

8181
```javascript
82-
import * as bi from 'azure-devops-node-api/interfaces/BuildInterfaces';
82+
import * as bi from "azure-devops-node-api/interfaces/BuildInterfaces";
8383

8484
async function run() {
85-
let project: string = 'myProject';
85+
let project: string = "myProject";
8686
let defs: bi.DefinitionReference[] = await build.getDefinitions(project);
8787

8888
defs.forEach((defRef: bi.DefinitionReference) => {

samples/build.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import * as cm from './common';
2-
import * as vm from 'azure-devops-node-api';
1+
import * as cm from "./common";
2+
import * as vm from "azure-devops-node-api";
33

4-
import * as ba from 'azure-devops-node-api/BuildApi';
5-
import * as bi from 'azure-devops-node-api/interfaces/BuildInterfaces';
4+
import * as ba from "azure-devops-node-api/BuildApi";
5+
import * as bi from "azure-devops-node-api/interfaces/BuildInterfaces";
66

77
export async function run() {
88
try
99
{
1010
let vsts: vm.WebApi = await cm.getWebApi();
1111
let vstsBuild: ba.IBuildApi = await vsts.getBuildApi();
1212

13-
cm.banner('Build Samples');
13+
cm.banner("Build Samples");
1414
let project = cm.getProject();
15-
console.log('project', project);
15+
console.log("project", project);
1616

1717
// list definitions
18-
cm.heading('Build Definitions for ' + project);
18+
cm.heading(`Build Definitions for ${project}`);
1919
let defs: bi.DefinitionReference[] = await vstsBuild.getDefinitions(project);
2020

21-
console.log('You have ' + defs.length + ' build definition(s)');
21+
console.log(`You have ${defs.length} build definition(s)`);
2222

2323
// save off last def to create a new definition below
2424
let lastDef: bi.BuildDefinition;
@@ -29,11 +29,11 @@ export async function run() {
2929
lastDef = def;
3030
let rep: bi.BuildRepository = def.repository;
3131

32-
console.log(defRef.name + ' (' + defRef.id + ') ' + 'repo ' + rep.type);
32+
console.log(`${defRef.name} (${defRef.id}) repo ${rep.type}`);
3333
}
3434

3535
// get top 10 successfully completed builds since 2016
36-
cm.heading('top 10 successfully completed builds for ' + project + 'project');
36+
cm.heading(`top 10 successfully completed builds for ${project}project`);
3737
let builds: bi.Build[] = await vstsBuild.getBuilds(
3838
project,
3939
null, // definitions: number[]
@@ -51,20 +51,20 @@ export async function run() {
5151
10 // top: number
5252
);
5353

54-
console.log(builds.length + ' builds returned');
54+
console.log(`${builds.length} builds returned`);
5555
builds.forEach((build: bi.Build) => {
56-
console.log(build.buildNumber, bi.BuildResult[build.result], 'on', build.finishTime.toDateString());
56+
console.log(build.buildNumber, bi.BuildResult[build.result], "on", build.finishTime.toDateString());
5757
});
5858

5959
// new definition
6060
if (lastDef && lastDef.process && lastDef.process.type === 1 /* Designer */) {
6161
let process = lastDef.process as bi.DesignerProcess;
6262
if (process.phases && process.phases.length > 0) {
6363
let phase = process.phases[0];
64-
cm.heading('creating a new definition');
64+
cm.heading("creating a new definition");
6565
let newDef: bi.BuildDefinition = <bi.BuildDefinition>{};
6666

67-
let newName: string = "api copy of " + lastDef.name;
67+
let newName = `api copy of ${lastDef.name}`;
6868
console.log("name", newName);
6969
newDef.name = newName;
7070

@@ -137,7 +137,7 @@ export async function run() {
137137
}
138138
}
139139
catch (err) {
140-
console.error('Error: ' + err.stack);
140+
console.error(`Error: ${err.stack}`);
141141
}
142142

143143
}

samples/buildArtifact.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
// A sample showing how to list VSTS build artifacts, and how to download a zip of a VSTS build artifact.
2-
import * as cm from './common';
3-
import * as vm from 'azure-devops-node-api';
4-
import * as fs from 'fs';
2+
import * as cm from "./common";
3+
import * as vm from "azure-devops-node-api";
4+
import * as fs from "fs";
55

6-
import * as ba from 'azure-devops-node-api/BuildApi';
7-
import * as bi from 'azure-devops-node-api/interfaces/BuildInterfaces';
6+
import * as ba from "azure-devops-node-api/BuildApi";
7+
import * as bi from "azure-devops-node-api/interfaces/BuildInterfaces";
88

99
export async function run() {
1010
try
1111
{
1212
const vsts: vm.WebApi = await cm.getWebApi();
1313
const vstsBuild: ba.IBuildApi = await vsts.getBuildApi();
1414

15-
cm.banner('Build Artifact Samples');
15+
cm.banner("Build Artifact Samples");
1616
const project = cm.getProject();
17-
console.log('project', project);
17+
console.log("project", project);
1818

1919
// get the latest successful build.
2020
cm.heading(`Get latest successful build for ${project} project`);
@@ -45,11 +45,11 @@ export async function run() {
4545

4646
let downloadableArtifact;
4747
for (const artifact of artifacts) {
48-
let additionalInfo = '';
49-
if (artifact.resource.type === 'FilePath') {
48+
let additionalInfo = "";
49+
if (artifact.resource.type === "FilePath") {
5050
additionalInfo = `UNC Path: ${artifact.resource.data}`;
5151
}
52-
else if (artifact.resource.type === 'Container') {
52+
else if (artifact.resource.type === "Container") {
5353
// As of June 2018, only `Container` artifacts can be downloaded as a zip.
5454
additionalInfo = `Downloadable: true.`;
5555
downloadableArtifact = artifact;
@@ -67,19 +67,19 @@ export async function run() {
6767
const fileStream = fs.createWriteStream(path);
6868
artifactStream.pipe(fileStream);
6969

70-
fileStream.on('close', () => {
70+
fileStream.on("close", () => {
7171
console.log(`Artifact '${downloadableArtifact.name}' downloaded to ${path}`);
7272
});
7373
}
7474
else {
75-
console.log('No downloadable artifact found.');
75+
console.log("No downloadable artifact found.");
7676
}
7777
}
7878
else {
79-
console.log('No successful builds found.');
79+
console.log("No successful builds found.");
8080
}
8181
}
8282
catch (err) {
83-
console.error('Error: ' + err.stack);
83+
console.error(`Error: ${err.stack}`);
8484
}
8585
}

samples/common.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
import * as vm from 'vso-node-api';
1+
import * as vm from "vso-node-api";
22
export declare function getWebApi(): vm.WebApi;

samples/common.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import * as vm from 'azure-devops-node-api';
2-
import * as lim from 'azure-devops-node-api/interfaces/LocationsInterfaces';
1+
import * as vm from "azure-devops-node-api";
2+
import * as lim from "azure-devops-node-api/interfaces/LocationsInterfaces";
33

44
function getEnv(name: string): string {
55
let val = process.env[name];
66
if (!val) {
7-
console.error(name + ' env var not set');
7+
console.error(`${name} env var not set`);
88
process.exit(1);
99
}
1010
return val;
1111
}
1212

1313
export async function getWebApi(): Promise<vm.WebApi> {
14-
let serverUrl = getEnv('API_URL');
14+
let serverUrl = getEnv("API_URL");
1515
return await this.getApi(serverUrl);
1616
}
1717

1818
export async function getApi(serverUrl: string): Promise<vm.WebApi> {
1919
return new Promise<vm.WebApi>(async (resolve, reject) => {
2020
try {
21-
let token = getEnv('API_TOKEN');
21+
let token = getEnv("API_TOKEN");
2222
let authHandler = vm.getPersonalAccessTokenHandler(token);
2323
let option = undefined;
2424

@@ -47,7 +47,7 @@ export async function getApi(serverUrl: string): Promise<vm.WebApi> {
4747

4848
let vsts: vm.WebApi = new vm.WebApi(serverUrl, authHandler, option);
4949
let connData: lim.ConnectionData = await vsts.connect();
50-
console.log('Hello ' + connData.authenticatedUser.providerDisplayName);
50+
console.log(`Hello ${connData.authenticatedUser.providerDisplayName}`);
5151
resolve(vsts);
5252
}
5353
catch (err) {
@@ -57,18 +57,18 @@ export async function getApi(serverUrl: string): Promise<vm.WebApi> {
5757
}
5858

5959
export function getProject(): string {
60-
return getEnv('API_PROJECT');
60+
return getEnv("API_PROJECT");
6161
}
6262

6363
export function banner(title: string): void {
64-
console.log('=======================================');
65-
console.log('\t' + title);
66-
console.log('=======================================');
64+
console.log("=======================================");
65+
console.log(`\t${title}`);
66+
console.log("=======================================");
6767
}
6868

6969
export function heading(title: string): void {
7070
console.log();
71-
console.log('> ' + title);
71+
console.log(`> ${title}`);
7272
}
7373

7474

0 commit comments

Comments
 (0)