Skip to content

Commit d815de8

Browse files
authored
feat: moves library to TypeScript code generation (#10)
1 parent eecc8b0 commit d815de8

File tree

4 files changed

+43
-35
lines changed

4 files changed

+43
-35
lines changed

generated,README.md,.eslintrc.yml/listBuildTriggers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async function listBuildTriggers(
3737
};
3838

3939
const [result] = await cb.listBuildTriggers(request);
40-
console.info(JSON.stringify(result.triggers, null, 2));
40+
console.info(JSON.stringify(result, null, 2));
4141
}
4242
// [END cloudbuild_list_build_triggers]
4343

generated,README.md,.eslintrc.yml/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
"node": ">=8"
1313
},
1414
"scripts": {
15-
"test": "mocha system-test --timeout=800000"
15+
"test": "c8 mocha system-test --timeout=800000"
1616
},
1717
"dependencies": {
1818
"@google-cloud/cloudbuild": "^0.1.0"
1919
},
2020
"devDependencies": {
21+
"c8": "^6.0.1",
2122
"chai": "^4.2.0",
2223
"mocha": "^6.0.0"
2324
}
24-
}
25+
}

generated,README.md,.eslintrc.yml/quickstart.js

+34-18
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
/**
2-
* Copyright 2019, Google, LLC.
3-
* Licensed under the Apache License, Version 2.0 (the "License");
4-
* you may not use this file except in compliance with the License.
5-
* You may obtain a copy of the License at
6-
*
7-
* http://www.apache.org/licenses/LICENSE-2.0
8-
*
9-
* Unless required by applicable law or agreed to in writing, software
10-
* distributed under the License is distributed on an "AS IS" BASIS,
11-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
* See the License for the specific language governing permissions and
13-
* limitations under the License.
14-
*/
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
1515

1616
'use strict';
1717

@@ -28,17 +28,33 @@ async function quickstart(
2828
const cb = new CloudBuildClient();
2929

3030
// Starts a build against the branch provided.
31-
const request = {
31+
const [resp] = await cb.runBuildTrigger({
3232
projectId,
3333
triggerId,
3434
source: {
35-
projectId: projectId,
35+
projectId,
3636
dir: './',
3737
branchName,
3838
},
39-
};
40-
await cb.runBuildTrigger(request);
39+
});
4140
console.info(`triggered build for ${triggerId}`);
41+
const [build] = await resp.promise();
42+
43+
const STATUS_LOOKUP = [
44+
'UNKNOWN',
45+
'Queued',
46+
'Working',
47+
'Success',
48+
'Failure',
49+
'Error',
50+
'Timeout',
51+
'Cancelled',
52+
];
53+
for (const step of build.steps) {
54+
console.info(
55+
`step:\n\tname: ${step.name}\n\tstatus: ${STATUS_LOOKUP[build.status]}`
56+
);
57+
}
4258
}
4359
// [END cloudbuild_quickstart]
4460

generated,README.md,.eslintrc.yml/system-test/samples.js

+5-14
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,19 @@ const PROJECT_ID = process.env.GCLOUD_PROJECT;
3030
const TRIGGER_ID =
3131
process.env.TRIGGER || 'c9033094-51a9-44c5-b3a0-1d882deb4464';
3232

33-
const {CloudBuildClient} = require('@google-cloud/cloudbuild');
34-
const cb = new CloudBuildClient();
35-
3633
describe('Sample Integration Tests', () => {
3734
it('should run quickstart.js', async () => {
38-
execSync(
39-
`node ./samples/quickstart.js ${PROJECT_ID} ${TRIGGER_ID} cloud-build-mvp`,
35+
const stdout = execSync(
36+
`node ./quickstart.js ${PROJECT_ID} ${TRIGGER_ID} cloud-build-mvp`,
4037
{cwd}
4138
);
42-
// confirm that a build has just been kicked off.
43-
const [builds] = await cb.listBuilds({
44-
projectId: PROJECT_ID,
45-
});
46-
const createTime = builds[0].createTime.seconds * 1000;
47-
const delta = Date.now() - createTime;
48-
const maxDelta = 20000; // last build was within 20s.
49-
assert.ok(delta < maxDelta, `delta ${delta} was > ${maxDelta}`);
39+
// build should have exited with success status.
40+
assert.include(stdout, 'status: Success');
5041
});
5142

5243
it('should run list-build-triggers.js', async () => {
5344
const stdout = execSync(
54-
`node ./samples/listBuildTriggers.js ${PROJECT_ID} ${TRIGGER_ID} cloud-build-mvp`,
45+
`node ./listBuildTriggers.js ${PROJECT_ID} ${TRIGGER_ID} cloud-build-mvp`,
5546
{cwd}
5647
);
5748
assert.include(stdout, 'Push-to-any-branch');

0 commit comments

Comments
 (0)