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

Support timestamps in parseRoute #3137

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
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
9 changes: 8 additions & 1 deletion source/github-helpers/parse-route.ts
Expand Up @@ -8,10 +8,17 @@ interface Pathname {
filePath: string;
toString: () => string;
}

const timeStampRegex = /.*@{(\d{4}([.\-/ ])\d{2}\2\d{2}T\d\d:\d\d:\d\dZ)}/;
function isTimeStamp(part1: string): boolean {
return timeStampRegex.test(decodeURIComponent(part1));
}

export default function parseRoute(pathname: string): Pathname {
const [user, repository, route, ...next] = pathname.replace(/^\/|\/$/g, '').split('/');
const parts = next.join('/');
const branch = getCurrentBranch();
next[0] = isTimeStamp(next[0]) ? branch + '/' : next[0];
const parts = next.join('/');
if (parts !== branch && !parts.startsWith(branch + '/')) {
Copy link
Member

@fregante fregante May 25, 2020

Choose a reason for hiding this comment

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

Maybe

Suggested change
if (parts !== branch && !parts.startsWith(branch + '/')) {
if (parts !== branch && !parts.startsWith(branch + '/') &&!isTimeStamp(next[0])) {

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Just this

Suggested change
if (parts !== branch && !parts.startsWith(branch + '/')) {
// Exclude extended revisions from being tested #3137 https://git-scm.com/docs/git-rev-parse#_specifying_revisions
if (parts !== branch && !parts.startsWith(branch + '/') && !/\^|~|@{/.test(next[0])) {

throw new Error('The branch of the current page must match the branch in the `pathname` parameter');
}
Expand Down