-
Notifications
You must be signed in to change notification settings - Fork 4
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 stash review support #1
base: master
Are you sure you want to change the base?
Changes from 3 commits
7ee6642
36eda62
359c8dc
3fb5d15
d5e0220
8c86b65
71cf51f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,62 @@ | ||
|
||
const bitbucket = { | ||
readBranch: () => document.querySelector("#id_source_group .branch a").textContent, | ||
readDomainOwnerAndProject: () => { | ||
const url = window.location.href; | ||
const regexp = /http[s]?:\/\/([a-zA-Z0-9]*\.[a-z]*)\/(\w*)\/([\w-]*).*/g; | ||
const matched = regexp.exec(url); | ||
const domain = matched[1]; | ||
const owner = matched[2]; | ||
const project = matched[3]; | ||
return { | ||
domain: domain, | ||
owner: owner, | ||
project: project | ||
}; | ||
} | ||
}; | ||
|
||
|
||
const stash = { | ||
readBranch: () => document.querySelector('div.pull-request-branches').textContent, | ||
readDomainOwnerAndProject: () => { | ||
|
||
let grabAfter = (array, after) => { | ||
return array[array.lastIndexOf(after) + 1]; | ||
}; | ||
|
||
const url = new URL(window.location.href); | ||
// example of URL to parse | ||
// https://stash.clearcode.cc/projects/CCADS/repos/backend/pull-requests/137/commits | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok. Now I see that for hosted solutions it might work, but for custom ones like yours we should have configuration. And I should definitely add support for github so I will now how much time I have spent on this review There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 exactly. So this would require a bit of work on the configuration part. |
||
const splitUrl = url.pathname.split('/'); | ||
return { | ||
domain: url.host, | ||
owner: grabAfter(splitUrl, 'projects'), | ||
project: grabAfter(splitUrl, 'repos') | ||
}; | ||
} | ||
}; | ||
|
||
const funcFactory = () => { | ||
let siteParser; | ||
const parsedUrl = new URL(window.location.href); | ||
|
||
if (parsedUrl.host.includes('stash')) { | ||
siteParser = stash; | ||
} else if (parsedUrl.host.includes('bitbucket')) { | ||
siteParser = bitbucket; | ||
} | ||
|
||
return { | ||
readDomainOwnerAndProject: siteParser.readDomainOwnerAndProject, | ||
readBranch: siteParser.readBranch | ||
}; | ||
}; | ||
|
||
function trackTime(keyPromise) { | ||
const {domain, owner, project} = readDomainOwnerAndProject(); | ||
const {readDomainOwnerAndProject, readBranch} = funcFactory(); | ||
const {entity, owner, project} = readDomainOwnerAndProject(); | ||
const branch = readBranch(); | ||
const entity = "bitbucket.org"; | ||
let havenOnlyScrolledInCurrentInterval = false; | ||
|
||
function scrollHandler() { | ||
|
@@ -15,30 +70,15 @@ function trackTime(keyPromise) { | |
} | ||
}, 30000); | ||
|
||
function readDomainOwnerAndProject() { | ||
const url = window.location.href; | ||
const regexp = /http[s]?:\/\/([a-zA-Z0-9]*\.[a-z]*)\/(\w*)\/([\w-]*).*/g; | ||
const matched = regexp.exec(url); | ||
const domain = matched[1]; | ||
const owner = matched[2]; | ||
const project = matched[3]; | ||
return {owner: owner, | ||
project: project}; | ||
} | ||
|
||
function readBranch() { | ||
return document.querySelector("#id_source_group .branch a").textContent; | ||
} | ||
|
||
function preparePayload(entity, type, project, branch, is_write) { | ||
return { | ||
entity: entity, | ||
type: type, | ||
time: (new Date).getTime()/1000, | ||
time: new Date().getTime()/1000, | ||
project: project, | ||
branch: branch, | ||
is_write: is_write, | ||
editor: "bitbucket.org" | ||
editor: entity | ||
}; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That won't work in current incarnation. The script will load for every page, which means it will measure time for every page and we don't want that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I guess this would have to stay more or less open like this and we have to guard it in the script itself