Skip to content

fix(ng-dev): properly encode URLs for GitHub queries in caretaker check #766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions ng-dev/caretaker/check/github.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,34 @@ describe('GithubQueriesModule', () => {
issueCount: 1,
nodes: [{url: 'http://github.com/owner/name/issue/1'}],
},
'query_with_colon': {
issueCount: 0,
nodes: [],
},
});
const module = new GithubQueriesModule(git, {
...mockNgDevConfig,
caretaker: {githubQueries: [{name: 'key name with spaces', query: 'issue: yes'}]},
caretaker: {
githubQueries: [
{name: 'key name with spaces', query: 'issue: yes'},
{name: 'query_with_colon', query: 'is:milestone'},
],
},
});

expect(await module.data).toEqual([
{
queryName: 'key name with spaces',
count: 1,
queryUrl: 'https://github.com/owner/name/issues?q=issue:%20yes',
queryUrl: 'https://github.com/owner/name/issues?q=issue%3A%20yes',
matchedUrls: ['http://github.com/owner/name/issue/1'],
},
{
queryName: 'query_with_colon',
count: 0,
queryUrl: 'https://github.com/owner/name/issues?q=is%3Amilestone',
matchedUrls: [],
},
]);
});
});
Expand Down
7 changes: 5 additions & 2 deletions ng-dev/caretaker/check/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,13 @@ export class GithubQueriesModule extends BaseModule<GithubQueryResults | void> {
const {owner, name: repo} = this.git.remoteConfig;

return results.map((result, i) => {
const query = queries[i];
const queryURLParam = encodeURIComponent(query.query);

return {
queryName: queries[i].name,
queryName: query.name,
count: result.issueCount,
queryUrl: encodeURI(`https://github.com/${owner}/${repo}/issues?q=${queries[i].query}`),
queryUrl: `https://github.com/${owner}/${repo}/issues?q=${queryURLParam}`,
matchedUrls: result.nodes.map((node) => node.url),
};
});
Expand Down