|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2021 Google LLC |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +const https = require('https'); |
| 19 | + |
| 20 | +async function logChangesets() { |
| 21 | + if (!process.env.GITHUB_EVENT_PATH) { |
| 22 | + console.log(`Couldn't find PR event payload.`); |
| 23 | + return; |
| 24 | + } |
| 25 | + |
| 26 | + const prPayload = require(process.env.GITHUB_EVENT_PATH); |
| 27 | + |
| 28 | + if (prPayload.pull_request.title !== 'Version Packages') { |
| 29 | + console.log(`Title of PR is not 'Version Packages'. Not logging.`); |
| 30 | + return; |
| 31 | + } |
| 32 | + |
| 33 | + // The PR's "Description" field. |
| 34 | + if (!prPayload.pull_request.body) { |
| 35 | + console.log(`Unable to find PR description.`); |
| 36 | + return; |
| 37 | + } |
| 38 | + const matches = prPayload.pull_request.body.match(/## firebase@([\d\.]+)/); |
| 39 | + const version = matches[1]; |
| 40 | + |
| 41 | + if (!version) { |
| 42 | + console.log(`Unable to extract Firebase version from PR description.`); |
| 43 | + return; |
| 44 | + } |
| 45 | + |
| 46 | + const data = JSON.stringify({ |
| 47 | + version, |
| 48 | + pr: prPayload.pull_request.number |
| 49 | + }); |
| 50 | + |
| 51 | + const options = { |
| 52 | + hostname: 'us-central1-feature-tracker-8ca2b.cloudfunctions.net', |
| 53 | + path: '/logChangesetPR', |
| 54 | + port: 443, |
| 55 | + method: 'POST', |
| 56 | + headers: { |
| 57 | + 'Content-Type': 'application/json' |
| 58 | + } |
| 59 | + }; |
| 60 | + |
| 61 | + return new Promise((resolve, reject) => { |
| 62 | + console.log(`Logging PR ${data.pr} with version ${data.version}.`); |
| 63 | + const req = https.request(options, res => { |
| 64 | + res.on('data', d => { |
| 65 | + process.stdout.write(d); |
| 66 | + }); |
| 67 | + res.on('end', resolve); |
| 68 | + }); |
| 69 | + |
| 70 | + req.on('error', error => reject(error)); |
| 71 | + |
| 72 | + req.write(data); |
| 73 | + req.end(); |
| 74 | + }); |
| 75 | +} |
| 76 | + |
| 77 | +logChangesets(); |
0 commit comments