Skip to content

Add tag-changelog-link feature - #1998

Merged
fregante merged 61 commits into
refined-github:masterfrom
hardikmodha:add_what_changed_since_prev_release
May 11, 2019
Merged

fregante merged 61 commits into
refined-github:masterfrom
hardikmodha:add_what_changed_since_prev_release

Conversation

@hardikmodha

@hardikmodha hardikmodha commented Apr 29, 2019 •

Copy link
Copy Markdown
Contributor

Should fix #966.

I tried to use the API but I couldn't find a way to fetch details of next and previous tags and fetching all tags at once wasn't feasible. (See discussion #966)

I've taken the following approach.

  1. First, I've extracted all tags, commit ids of those tags.

  2. Now, iterating over each tag, I see if the next tag has the different commit id. (Given the fact that we can have multiple tags on the same commit id).

  3. If the next tag has different commit id, then I further check whether the tags are namespaced or not. If the namespace is the same then pick that tag for comparison.

  4. If the next tag has same commit id then that tag is skipped and we check remaining tags.

  5. For the last tag, I fetch the next page using fetchDom and perform the same steps as mentioned above. If a tag to compare is not found on the next page then we skip the tag.

Tested it on the following (and many other) repos.

  1. https://github.com/parcel-bundler/parcel/releases (It has multiple, namespaced and normal semver style tags)
  2. https://github.com/tensorflow/tensorflow/releases (With Alpha, Beta kind of tags)
  3. https://github.com/facebook/react/releases

The feature works on the following pages:

  1. releases listing: e.g. https://github.com/parcel-bundler/parcel/releases
  2. tags listing: e.g. https://github.com/parcel-bundler/parcel/tags
  3. Single tag pages: https://github.com/parcel-bundler/parcel/releases/tag/v1.10.3

Limitations:

  1. Namespaced tags are only checked within the single page to find it's previous tag. Update: Now we check on the next page, too.

  2. For the last tag on the page, we only check on the next page to find the previous tag. Update: For all the tags on any page, we also check the next page for finding its previous tag.

  3. The tags are not semantically compared. But we can easily implement it.

PS: Please suggest a better way (if you have) to solve this issue. I would be more than happy to implement it. :)

1. Edge cases not yet handled.
2. Currently only fetches the next release from the sequence and adds the compare link.
3. For the last tag on any page, uses fetchDom to retrieve the next page and extracts
the tag from it.
Now, If there are multiple tags on the same commit, we traverse
all the commits present on the single page and select the next
commit on which different tag is present.

Still not handling the case of namespaced tags.
The compare link is generated as follows

1. We find a commit having diffrent commit hash.

2. Once such a commit is found, we check the namespace.
If namespaces are same, we use that tag as the previous tag else
we try to look further for tag of same namespace.

3. If tag having same namespace is not found on the current page, we
use the next commit having different hash.

4. For the last tag on the page, we fetch the next page and follow the
same process as above.
@hardikmodha

Copy link
Copy Markdown
Contributor Author

@bfred-it @sindresorhus Can you please take a look? Thanks!

Comment thread source/content.ts Resolved

@fregante fregante left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is lengthy, consider reducing repetition where possible and skip conditions.

For example:

  • getCommitIdSelector and getTagSelector can be skipped if you just use commitAnchorSelector and tagAnchorSelector respectively? This lets you skip a lot of code and even isReleasesListPage and isTagsListPage themselves
  • the code after allTagsAnchor and nextPageAllTagsAnchor is nearly identical and can probably be merged.

Generally, instead of creating multiple large code paths (if (){20 lines of code} else {20 lines of code}), try to make standardize the input content. e.g.

for each link on the page (whether it’s one or 20)
	compareLink = findNextLink() || findNextLink(memoizedFetchNextPage())
	add compareLink next to title
end for

findNextLink() {
	if tag has prefix
		return query(href ^= prefix)
	end if
	
	return query(:not(href ^= prefix))
}

Also always use for-of and not a regular for

I'm confident this code can be at least halved :)

I think this article improved my code: https://medium.com/@bartobri/applying-the-linus-tarvolds-good-taste-coding-requirement-99749f37684a


Position: I was expecting this link to be on the commit | zip | tar.gz line and something more clear than ... (I didn't even see the link at first, that ... is generally used to expand the content)

1. Simplified the regex
2. Simplified the tag and commit selectors and removed their unnecessary methods
3. Used the GitHub's diff icon for displaying comparison link
4. Better position for compare link
1. Removed conditional checks before looking for previous tags. All
tags are now treated equally whether they are on releases, tag listing
or single tag page.
2. Use the single loop to go through the tags irrespective of their index.
It also improved the probability of finding the previous tag to compare
as we now look into the next page for all the tags.
@hardikmodha

Copy link
Copy Markdown
Contributor Author
  • getCommitIdSelector and getTagSelector can be skipped if you just use commitAnchorSelector and tagAnchorSelector respectively? This lets you skip a lot of code and even isReleasesListPage and isTagsListPage themselves

Done. Simplified the commit id and tag selectors. Also, removed the checks for isReleaseListPage and isTagsListPage by using the common classname as selector which was present on both the pages.

  • the code after allTagsAnchor and nextPageAllTagsAnchor is nearly identical and can probably be merged.

Now, Appending the next page tags into the same array and iterating only once. Check for the last tag is also removed.

Also always use for-of and not a regular for

Here, I need an index of the item so that I can start looking for the tags to match just after that index. You can take a look from Line no 36 and Line no 62.

Position: I was expecting this link to be on the commit | zip | tar.gz line and something more clear than ... (I didn't even see the link at first, that ... is generally used to expand the content)

Initially, I had chosen the same. The same line as commit | zip | tar.gz and for the releases just below the commit hash. (As displayed in the screenshot)

1ec2a437-cc8e-45eb-97f7-4d15ac433700

But there was some miscommunication due to #966 (comment) and I put the link on ... 😓.

@hardikmodha

Copy link
Copy Markdown
Contributor Author

@bfred-it Please take a look at new changes and suggest me if anything still needs to be changed. :)

@hardikmodha

hardikmodha commented May 5, 2019 •

Copy link
Copy Markdown
Contributor Author

Using your suggested approach as for edge case (5c0d57f) my approach silently failed but your approach threw an error which I really liked which led me to realize what mistake I was making. Also in your suggested approach, we only need to iterate only once to extract tag and commit details. (Removed the big comment which now I think is unnecessary.)

Let me know if any more changes are needed. Thanks :)

@fregante fregante left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you and sorry for all the reviews ❤️

Comment thread source/features/tag-changelog-link.tsx Resolved
Comment thread source/features/tag-changelog-link.tsx Resolved
Comment thread source/features/tag-changelog-link.tsx Resolved
Comment thread source/features/tag-changelog-link.tsx Resolved
@hardikmodha

Copy link
Copy Markdown
Contributor Author

Thank you and sorry for all the reviews

Haha...No need for sorry. I learned a lot through your and Sindre's hardcore reviews. Most of the time I (or any new person) is focused on making something to work and we forget some scenarios or make some silly mistakes. That's where you guys come into the picture. Just making something to work is not enough. I really appreciate your and Sindre's attitude towards perfectness. :)

@fregante fregante left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, perhaps this should use tiny-version-compare to ensure that the tag we're comparing to is actually lower than the current one.

For example on: https://github.com/tensorflow/tensorflow/releases
The tag right after v1.12.1 is TensorFlow 2.0.0-alpha0 and the generated link shouldn't be:

tensorflow/tensorflow@v2.0.0-alpha0...v1.12.1

but it should compare it against v1.12.0, further down the page

tensorflow/tensorflow@v1.12.0...v1.12.1

Comment thread source/features/tag-changelog-link.tsx Resolved
Comment thread source/features/tag-changelog-link.css Resolved
@hardikmodha

Copy link
Copy Markdown
Contributor Author

Also, perhaps this should use tiny-version-compare to ensure that the tag we're comparing to is actually lower than the current one.

For example on: https://github.com/tensorflow/tensorflow/releases
The tag right after v1.12.1 is TensorFlow 2.0.0-alpha0 and the generated link shouldn't be:

tensorflow/[email protected]

but it should compare it against v1.12.0, further down the page

tensorflow/[email protected]

Yep, you are right. I am aware of this limitation and have already mentioned it in a description. I didn't look for any packages (pure out of laziness maybe) 😅. Thanks for the tiny-version-compare suggestion. This wekend, I'm out so won't be able to work on it. Next week I'll give it a try.

fregante added 2 commits May 10, 2019 13:22
`.release-main-section .commit` works on tags in releases list, whether open or collapsed, avoiding the "dummy release" uncollapser element because that doesn't include a `.commit` element.

Tested on https://github.com/facebook/react/releases?after=v16.7.0
@fregante fregante self-assigned this May 10, 2019
@fregante fregante removed their assignment May 10, 2019

@sindresorhus sindresorhus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great 👍

@fregante
fregante merged commit bcb9ed2 into refined-github:master May 11, 2019
@fregante

Copy link
Copy Markdown
Member

Hallelujah! Finally we merged it. Thanks for this feature!

@hardikmodha

hardikmodha commented May 14, 2019 •

Copy link
Copy Markdown
Contributor Author

Woahhh, Thanks for refining the feature. ❤️ I just returned today and saw this merged!!! 🎉

But seems like there is a small issue. Tags are not being compared with a namespace.

Screen Shot 2019-05-14 at 8 48 20 PM
It should compare parcel-bundler with it's matching previous tag, not with the parcel-integration. The tag name is not being decoded before extracting version and namespace using parseTags.

@hardikmodha

Copy link
Copy Markdown
Contributor Author

Also, I noticed a behavior with version aware comparison. It is comparing the first previous tag and not the closest matching previous release.

e.g. On https://github.com/flutter/flutter/releases?after=v1.5.1 releases page.

Screen Shot 2019-05-14 at 8 59 04 PM

It should compare v1.4.17 with v1.4.16 and not v1.4.9-hotfix.1. What do you think?

@hardikmodha
hardikmodha deleted the add_what_changed_since_prev_release branch May 14, 2019 15:56
@fregante fregante mentioned this pull request May 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Link to "What changed since the previous release?"

3 participants