generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgcp.js
31 lines (24 loc) · 947 Bytes
/
gcp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const core = require('@actions/core');
const { FieldValue, Firestore } = require('@google-cloud/firestore');
const db = new Firestore();
let gcp = async function (table_name, pr) {
const table = db.collection(table_name);
core.debug(`Checking for active environment assigned to ${pr}...`);
const envs = await table.where('pull_requests', 'array-contains', pr).where('in_use', '==', true).limit(1).get();
if (!envs.empty) {
const env = envs.docs[0];
const data = env.data();
const in_use = data.pull_requests.length > 1;
const branch = in_use ? data.branch : '';
core.debug(`Found QA environment in use by ${data.pull_requests}`);
core.debug(`Removing ${pr} from QA environment ...`);
await env.ref.update({
in_use,
branch,
pull_requests: FieldValue.arrayRemove(pr),
});
} else {
core.debug(`No active environment found for ${pr}. Nothing to do.`);
}
}
module.exports = gcp;