-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Revive the changelog Signed-off-by: Joe Farro <[email protected]> * Add helper script to generate CHANGELOG entries Signed-off-by: Joe Farro <[email protected]> * One more changelog item, fix date typo Signed-off-by: Joe Farro <[email protected]> * Fix phrasing in changelog Signed-off-by: Joe Farro <[email protected]>
- Loading branch information
Showing
4 changed files
with
168 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#!/usr/bin/env node | ||
|
||
// Copyright (c) 2019 Uber Technologies, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// This code will generate changelog entries | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
const fetch = require('isomorphic-fetch'); | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
const jsdom = require('jsdom'); | ||
|
||
const DOMAIN = 'https://github.com/'; | ||
|
||
const URL_PARTS = [`${DOMAIN}jaegertracing/jaeger-ui/pulls?page=`, '&q=is%3Apr+is%3Amerged&utf8=%E2%9C%93']; | ||
|
||
function getData(elm) { | ||
const title = elm.querySelector('[data-hovercard-type="pull_request"]').textContent; | ||
const url = elm.querySelector('[data-hovercard-type="pull_request"]').href; | ||
const pid = /#\d+/g.exec(elm.querySelector('.opened-by').textContent)[0]; | ||
const user = elm.querySelector('[data-hovercard-type="user"]').textContent; | ||
const dateMerged = new Date(elm.querySelector('[datetime]').getAttribute('datetime')); | ||
return { title, url, pid, user, dateMerged }; | ||
} | ||
|
||
function fmtPr(data) { | ||
const { title, url, pid, user } = data; | ||
return `- ${title} ([@${user}](https://github.com/${user}) in [${pid}](${url}))`; | ||
} | ||
|
||
function compareMergedDates(a, b) { | ||
return a.dateMerged > b.dateMerged ? 1 : Number(a.dateMerged === b.dateMerged) - 1; | ||
} | ||
|
||
function getPrData(document) { | ||
const wrapper = document.querySelector('[aria-label="Issues"]'); | ||
const issues = [].slice.call(wrapper.querySelectorAll('.js-issue-row')); | ||
const okIssues = issues.filter(elm => !elm.querySelector('[aria-label*="Closed"]')); | ||
return okIssues.map(getData); | ||
} | ||
|
||
function getMergedPrs(page) { | ||
const _page = page == null || isNaN(page) ? 1 : Number(page); | ||
const url = URL_PARTS.join(_page); | ||
return ( | ||
fetch(url) | ||
.then(resp => resp.text()) | ||
.then(textContent => { | ||
const dom = new jsdom.JSDOM(textContent, { url: DOMAIN }); | ||
return getPrData(dom.window.document); | ||
}) | ||
// eslint-disable-next-line no-console | ||
.catch(error => console.error(error)) | ||
); | ||
} | ||
|
||
function getChangelog(pages) { | ||
const _pages = pages == null || isNaN(pages) ? 1 : Number(pages); | ||
const promises = []; | ||
for (let i = 1; i <= _pages; i++) { | ||
promises.push(getMergedPrs(i)); | ||
} | ||
return ( | ||
Promise.all(promises) | ||
.then(groups => [].concat(...groups)) | ||
.then(items => { | ||
items.sort(compareMergedDates); | ||
items.reverse(); | ||
return items; | ||
}) | ||
// eslint-disable-next-line no-console | ||
.catch(error => console.error(error)) | ||
); | ||
} | ||
|
||
if (require.main === module) { | ||
getChangelog(process.argv[2] || 1) | ||
// eslint-disable-next-line no-console | ||
.then(items => console.log(items.map(fmtPr).join('\n\n'))) | ||
// eslint-disable-next-line no-console | ||
.catch(error => console.error(error)); | ||
} else { | ||
module.exports = getChangelog; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters