Skip to content

Commit

Permalink
🏗 Decode url params for release tagger (#36796)
Browse files Browse the repository at this point in the history
* decode and make nice

* tests
  • Loading branch information
estherkim committed Nov 5, 2021
1 parent 73e17ff commit 0f65ac4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
5 changes: 3 additions & 2 deletions build-system/release-tagger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

const dedent = require('dedent');
const {action, base, channel, head, sha, time} = require('minimist')(
const {action, base, channel, head, sha, timeParam} = require('minimist')(
process.argv.slice(2),
{
string: ['head', 'base'],
Expand All @@ -29,6 +29,7 @@ const {publishRelease, rollbackRelease} = require('./update-release');
* @return {Promise<void>}
*/
async function _promote() {
const time = decodeURIComponent(timeParam);
log(
cyan(dedent`Release tagger triggered with inputs:
action: ${magenta(action)}
Expand All @@ -49,7 +50,7 @@ async function _promote() {
const {'html_url': url} = await makeRelease(head, base, channel, sha);
log('Created release', magenta(head), 'at', cyan(url));
} else {
log('Found release', magenta(head), 'at', cyan(release.url));
log('Found release', magenta(head), 'at', cyan(release['html_url']));
}

if (['stable', 'lts'].includes(channel)) {
Expand Down
12 changes: 6 additions & 6 deletions build-system/release-tagger/test/update-issue-tracker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test('create', async (t) => {
'{"query":"query {' +
'search(query:\\"repo:ampproject/amphtml ' +
'in:title Release 2109080123000\\", type: ISSUE, first: 1) ' +
'{ nodes { ... on Issue { number title body }}}}"}'
'{ nodes { ... on Issue { number title body url }}}}"}'
)
.reply(200, {data: {search: {}}});

Expand Down Expand Up @@ -57,7 +57,7 @@ test('mark task complete', async (t) => {
'{"query":"query {' +
'search(query:\\"repo:ampproject/amphtml ' +
'in:title Release 2109080123000\\", type: ISSUE, first: 1) ' +
'{ nodes { ... on Issue { number title body }}}}"}'
'{ nodes { ... on Issue { number title body url }}}}"}'
)
.reply(200, {
data: {
Expand Down Expand Up @@ -89,7 +89,7 @@ test('mark task complete', async (t) => {
'{"query":"query {' +
'search(query:\\"repo:ampproject/amphtml ' +
'in:title Release 2109010123000\\", type: ISSUE, first: 1) ' +
'{ nodes { ... on Issue { number title body }}}}"}'
'{ nodes { ... on Issue { number title body url }}}}"}'
)
.reply(200, {
data: {
Expand Down Expand Up @@ -150,23 +150,23 @@ test('add cherrypick tasks', async (t) => {
'{"query":"query {' +
'search(query:\\"repo:ampproject/amphtml ' +
'in:title Release 2109080123002\\", type: ISSUE, first: 1) ' +
'{ nodes { ... on Issue { number title body }}}}"}'
'{ nodes { ... on Issue { number title body url }}}}"}'
)
.reply(200, {data: {search: {}}})
.post(
'',
'{"query":"query {' +
'search(query:\\"repo:ampproject/amphtml ' +
'in:title Release 2109080123001\\", type: ISSUE, first: 1) ' +
'{ nodes { ... on Issue { number title body }}}}"}'
'{ nodes { ... on Issue { number title body url }}}}"}'
)
.reply(200, {data: {search: {}}})
.post(
'',
'{"query":"query {' +
'search(query:\\"repo:ampproject/amphtml ' +
'in:title Release 2109080123000\\", type: ISSUE, first: 1) ' +
'{ nodes { ... on Issue { number title body }}}}"}'
'{ nodes { ... on Issue { number title body url }}}}"}'
)
.reply(200, {
data: {
Expand Down
12 changes: 11 additions & 1 deletion build-system/release-tagger/update-issue-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

const dedent = require('dedent');
const {createIssue, getIssue, updateIssue} = require('./utils');
const {cyan, magenta} = require('kleur/colors');
const {log} = require('../common/logging');

const CHANNEL_NAMES = {
'beta-opt-in': 'Experimental and Beta (opt-in) channels',
Expand Down Expand Up @@ -133,10 +135,18 @@ async function createOrUpdateTracker(head, base, channel, time) {
tracker.checkTask(channel, time);
const {footer, header, label, main, title} = tracker;
const body = `${header}\n\n${main}\n\n${footer}`;
return await createIssue(body, label, title);
const newIssue = await createIssue(body, label, title);
log(
'Created issue tracker',
magenta(newIssue.title),
'at',
cyan(newIssue['html_url'])
);
return;
}

// check task
log('Found issue tracker', magenta(issue.title), 'at', cyan(issue.url));
const tracker = new IssueTracker(head, base, issue.body, issue.number);
if (isCherrypick) {
tracker.addCherrypickTasks(channel);
Expand Down
7 changes: 4 additions & 3 deletions build-system/release-tagger/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ async function _runQueryInBatches(queryType, queries) {
* @param {string} title
* @return {Promise<Object>}
*/
function createIssue(body, label, title) {
return octokit.rest.issues.create({
async function createIssue(body, label, title) {
const {data} = await octokit.rest.issues.create({
owner,
repo,
title,
body,
labels: [label],
});
return data;
}

/**
Expand Down Expand Up @@ -100,7 +101,7 @@ async function getIssue(title) {
const search = dedent`\
search(query:"repo:${owner}/${repo} in:title ${title}", \
type: ISSUE, first: 1) { nodes { ... on Issue \
{ number title body }}}`;
{ number title body url }}}`;
const query = `query {${search}}`;
const response = await graphqlWithAuth({query});
if (response.search?.nodes) {
Expand Down
1 change: 1 addition & 0 deletions build-system/test-configs/forbidden-terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@ const forbiddenTermsSrcInclusive = {
'use tryDecodeUriComponent from src/url.js',
allowlist: [
'3p/integration-lib.js',
'build-system/release-tagger/index.js',
'examples/pwa/pwa.js',
'validator/js/engine/parse-url.js',
'validator/js/engine/validator.js',
Expand Down

0 comments on commit 0f65ac4

Please sign in to comment.