Skip to content
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

Add tag-changelog-link feature #1998

Merged
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
512d793
Adding compare link separately.
hardikmodha Apr 28, 2019
e38619a
Basic version of what-changes-since-previous-release ready
hardikmodha Apr 28, 2019
6b9e084
More specific selectors to avoid false matches
hardikmodha Apr 28, 2019
4d29ac8
Handling different tags on same commit in a single page
hardikmodha Apr 28, 2019
2063218
Removed unnecessary methods and reorganized a bit
hardikmodha Apr 28, 2019
721b555
Considering the namespaced tags
hardikmodha Apr 28, 2019
b3200cd
Move page detection functions to page-detect.ts
hardikmodha Apr 28, 2019
4d21eea
Lint fixes and minor UX improvement
hardikmodha Apr 28, 2019
9c5f60b
Modify selector to make it work with single release page
hardikmodha Apr 28, 2019
117d04f
Comparing tags in a better way
hardikmodha Apr 29, 2019
53ba546
Use regex to compare tag hierarchy
hardikmodha Apr 29, 2019
f56d01e
Rename function
hardikmodha Apr 29, 2019
fc33877
Display compare link on single tag pages
hardikmodha Apr 29, 2019
506aad2
Merge branch 'master' into add_what_changed_since_prev_release
hardikmodha Apr 29, 2019
b9d1aee
Few renames
hardikmodha Apr 29, 2019
6baf0a6
Removed extra code
hardikmodha Apr 30, 2019
4ff927a
Further simplify the code
hardikmodha Apr 30, 2019
73b4247
Minor style fixes
hardikmodha Apr 30, 2019
7a4ccdd
Minor changes and few renames
hardikmodha Apr 30, 2019
6b24bc8
Lint fixes and remove unused code
hardikmodha Apr 30, 2019
484fe16
🤦 Delete local file
hardikmodha Apr 30, 2019
8ea9fea
PR Feedback to improve the code and to make it more concise
hardikmodha May 1, 2019
be0d3b3
Simplified the regex and concise code
hardikmodha May 1, 2019
d5cb6b6
Import css file in the feature file
hardikmodha May 1, 2019
123d47a
Feature doc
hardikmodha May 1, 2019
176c61c
Rename to 'tag-changelog-link'
hardikmodha May 1, 2019
055d5c4
Get rid of css file and use GitHub's defined CSS classes
hardikmodha May 1, 2019
f8ca2a3
Inline JSX
hardikmodha May 1, 2019
41a53f2
Add tooltip
hardikmodha May 1, 2019
fb88b25
Fix issue on Firefox
fregante May 1, 2019
088d5f1
Regex not needed to extract commit id and tag
hardikmodha May 1, 2019
6b2c871
Add comment explaining the reason for location.origin
hardikmodha May 1, 2019
e81bd47
Add comment explaining the reason for location.origin
hardikmodha May 1, 2019
a069e9c
Query once; merge functions; avoid indexes when possible
fregante May 2, 2019
228df3f
Fix tag selector
fregante May 2, 2019
29aae28
Avoid jumps caused by margins
fregante May 2, 2019
affb1d3
Merge remote-tracking branch 'origin' into pr/1998
fregante May 2, 2019
14f7fc5
Merge branch 'master' of github.com:sindresorhus/refined-github into …
hardikmodha May 2, 2019
5cf2b78
Merge branch 'add_what_changed_since_prev_release' of github.com:Hard…
hardikmodha May 2, 2019
dbfe9bb
Add feature screenshot in readme
hardikmodha May 2, 2019
6782223
Fix the commit id selector to avoid false matches
hardikmodha May 2, 2019
b50f7b3
Fixes to make it work with custom tag names.
hardikmodha May 4, 2019
758132b
Remove flex-grow on smaller windows and add myself as CODEOWNER
hardikmodha May 5, 2019
622ef32
Merge branch 'master' into add_what_changed_since_prev_release
hardikmodha May 5, 2019
0e9f33d
Simplify selectors
hardikmodha May 5, 2019
c5f4f5a
Use select.all
hardikmodha May 5, 2019
84d31c8
Merge branch 'add_what_changed_since_prev_release' of github.com:Hard…
hardikmodha May 5, 2019
5c0d57f
Handled an edge case
hardikmodha May 5, 2019
3e77c4c
Use suggested approach as we need to iterate only once to fetch tag a…
hardikmodha May 5, 2019
7ef21c2
Move namespace extraction to a method and simplify selectors
hardikmodha May 5, 2019
5f2ef15
Merge branch 'master' into add_what_changed_since_prev_release
hardikmodha May 5, 2019
101021d
Lint
hardikmodha May 5, 2019
89d649b
Move decodeURIComponent to tooltip text
hardikmodha May 5, 2019
c217b29
Update select-dom to fix types
fregante May 10, 2019
ceb26cd
Shorten selectors and update+merge comments
fregante May 10, 2019
04a95b4
Handle `Verified` label on mobile release pages
fregante May 10, 2019
5bbd88d
Use `icons.diff()` instead of `diff()`
fregante May 10, 2019
073fb8e
Extract and add tests for tag namespace parser
fregante May 10, 2019
c4788d2
Improve variable names and types
fregante May 10, 2019
407289b
Ensure that the version is actually a lower one
fregante May 10, 2019
aac7d48
Update readme copy
fregante May 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
@@ -1,4 +1,5 @@
source/features/filter-pr-by-build-status.tsx @HardikModha
source/features/tags-dropdown.tsx @HardikModha
source/features/tag-changelog-link.tsx @HardikModha
source/features/link-to-file-in-file-history.tsx @HardikModha
source/features/default-to-rich-diff.tsx @idasbiste
1 change: 1 addition & 0 deletions readme.md
Expand Up @@ -203,6 +203,7 @@ GitHub Enterprise is also supported. More info in the options.
- [Follow file renames in commits lists.](https://user-images.githubusercontent.com/1402241/54799957-7306a280-4c9a-11e9-86de-b9764ed93397.png)
- [Edit files straight from a repo’s list by clicking their icon.](https://user-images.githubusercontent.com/1402241/56370462-d51cde00-622d-11e9-8cd3-8a173bd3dc08.png)
- [Search or select tags from a dropdown in the `Releases` page.](https://user-images.githubusercontent.com/22439276/56373231-27ee9980-621e-11e9-9b21-601919d3dddf.png)
- [See what has changed since the previous release](https://user-images.githubusercontent.com/1402241/57081611-ad4a7180-6d27-11e9-9cb6-c54ec1ac18bb.png)
- [Link to file itself in the history pages](https://user-images.githubusercontent.com/22439276/57195061-b88ddf00-6f6b-11e9-8ad9-13225d09266d.png)

### Previously part of Refined GitHub
Expand Down
1 change: 1 addition & 0 deletions source/content.ts
Expand Up @@ -99,6 +99,7 @@ import './features/tags-dropdown';
import './features/filter-pr-by-build-status';
import './features/edit-files-faster';
import './features/hide-disabled-milestone-sorter';
import './features/tag-changelog-link';
import './features/link-to-file-in-file-history';

import './features/scrollable-code-and-blockquote.css';
Expand Down
3 changes: 3 additions & 0 deletions source/features/tag-changelog-link.css
@@ -0,0 +1,3 @@
.release div.release-header > ul > li {
flex-grow: 0 !important;
fregante marked this conversation as resolved.
Show resolved Hide resolved
}
113 changes: 113 additions & 0 deletions source/features/tag-changelog-link.tsx
@@ -0,0 +1,113 @@
/*
Adds a compare link on each releases/tags/single tag page so that you can see what has changed since the previous release.
If the tags are namespaced then it tries to get the previous release of the same namespaced tag.

See it in action at: https://github.com/parcel-bundler/parcel/releases
*/
import './tag-changelog-link.css';
import React from 'dom-chef';
import select from 'select-dom';
import features from '../libs/features';
import fetchDom from '../libs/fetch-dom';
import {diff} from '../libs/icons';
fregante marked this conversation as resolved.
Show resolved Hide resolved
import {isSingleTagPage} from '../libs/page-detect';
import {getRepoPath, getRepoURL} from '../libs/utils';

type TagDetails = {
element: HTMLElement;
commit: string;
tag: string;
}

async function getNextPage(): Promise<DocumentFragment> {
const nextPageLink = select<HTMLAnchorElement>('.pagination a:last-child');
if (nextPageLink) {
return fetchDom(nextPageLink.href);
}

if (isSingleTagPage()) {
const [, tag = ''] = getRepoPath()!.split('releases/tag/', 2); // Already URL-encoded
return fetchDom(`/${getRepoURL()}/tags?after=${tag}`);
}

return new DocumentFragment();
}

async function init(): Promise<void | false> {
if (select.exists('.blankslate')) {
return false;
}

const tagRegex = /\/releases\/tag\/(.*)/;
const documents = [document, await getNextPage()] as any; // TODO: fix select-dom types to accept mixed arrays

// not(.js-timeline-tags-expander) is needed as there can be some collapsed tags
// See https://github.com/facebook/react/releases?after=v16.7.0 for an example
const tagContainerSelector = '.release, .Box-row .commit, .release-entry .release-main-section:not(.commit):not(.js-timeline-tags-expander)';

// These selectors need to work on:
// https://github.com/facebook/react/tags (tags list)
// https://github.com/facebook/react/releases (releases list)
// https://github.com/parcel-bundler/parcel/releases (releases list without release notes)

const allTags: TagDetails[] = select.all(tagContainerSelector, documents).map(element => ({
element,
tag: select<HTMLAnchorElement>('[href*="/releases/tag/"]', element)!.pathname.match(tagRegex)![1],
commit: select('[href*="/commit/"]', element)!.textContent!.trim()
}));

for (const [index, container] of allTags.entries()) {
const previousTag = getPreviousTag(index, allTags);

if (previousTag !== false) {
const unorderedLists = select.all('.commit > ul.f6, .commit > .release-header > ul, div:first-child > ul', container.element);

for (const list of unorderedLists) {
list.append(
<li className={list.lastElementChild!.className}>
<a
className="muted-link tooltipped tooltipped-n"
aria-label={'See changes since ' + decodeURIComponent(previousTag)}
href={`/${getRepoURL()}/compare/${previousTag}...${allTags[index].tag}`}
>
{diff()} Changelog
</a>
</li>
);
}
}
}
}

// If tag is `@parcel/integration-tests@1.12.2` then namespace is `@parcel/integration-tests`
const getNameSpace = (tag: string): string => tag.split(/@[^@]+$/)[0];

const getPreviousTag = (index: number, allTags: TagDetails[]): string | false => {
let previousTag: string | false = false;

for (let i = index + 1; i < allTags.length; i++) {
if (allTags[i].commit === allTags[index].commit) {
continue;
}

// Ensure that they have the same namespace. e.g. `parcel@1.2.4` and `parcel@1.2.3`
if (getNameSpace(allTags[i].tag) === getNameSpace(allTags[index].tag)) {
return allTags[i].tag;
}

if (previousTag === false) {
previousTag = allTags[i].tag;
}
}

return previousTag;
};

features.add({
id: 'tag-changelog-link',
include: [
features.isReleasesOrTags
],
load: features.onAjaxedPages,
init
});
2 changes: 2 additions & 0 deletions source/libs/page-detect.ts
Expand Up @@ -97,6 +97,8 @@ export const isTrending = (): boolean => location.pathname === '/trending' || lo

export const isUserProfile = (): boolean => select.exists('.user-profile-nav');

export const isSingleTagPage = (): boolean => /^(releases\/tag)/.test(getRepoPath()!);

export const hasComments = (): boolean =>
isPR() ||
isIssue() ||
Expand Down
10 changes: 10 additions & 0 deletions test/page-detect.ts
Expand Up @@ -380,3 +380,13 @@ test('isRepoSearch', urlMatcherMacro, pageDetect.isRepoSearch, [
'https://github.com/sindresorhus/search',
'https://github.com/search'
]);

test('isSingleTagPage', urlMatcherMacro, pageDetect.isSingleTagPage, [
'https://github.com/sindresorhus/refined-github/releases/tag/v1.0.0-beta.4',
'https://github.com/sindresorhus/refined-github/releases/tag/0.2.1'
], [
'https://github.com/sindresorhus/refined-github/tags',
'https://github.com/sindresorhus/refined-github/releases',
'https://github.com/sindresorhus/refined-github',
'https://github.com/sindresorhus/refined-github/graphs'
]);