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
Refactor deck to use /prowjobs.js #7301
Refactor deck to use /prowjobs.js #7301
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: katerinapat Assign the PR to them by writing The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/ok-to-test |
completionMoment = new moment(completionTime), | ||
d = moment.duration(completionMoment.diff(startMoment)); | ||
|
||
return d.hours() + "h" + d.minutes() + "m" + d.seconds() + "s"; |
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.
d.format()
?
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.
Duration object seems not to have format()
.
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.
Yeah, see moment/moment#1048.
This is wrong for jobs that take too long, and it will look weird to have a bunch of 0h jobs.
var out = d.seconds() + 's';
if (d.asHours() >= 1)
out = Math.floor(d.asHours()) + 'h' + d.minutes() + 'm' + out;
else if (d.minutes() >= 1)
out = d.minutes() + 'm' + out;
return out;
prow/cmd/deck/static/script.js
Outdated
function createTimeCell(id, time) { | ||
var momentTime = moment.unix(time); |
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.
Not immediately obvious why this was wrong?
prow/cmd/deck/static/script.js
Outdated
if (!repo || repo === build.spec.refs.repo) { | ||
opts.jobs[build.spec.job] = true; | ||
if (build.spec.type === "presubmit") { | ||
opts.authors[build.spec.refs.pulls[0]['author']] = true; |
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.
Do we want to not squash the list of pulls for batches?
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.
is there any case that build.spec.refs.pulls can be null
or undefined
?
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.
Yes, in periodic and postsubmit jobs there will be no pulls
prow/cmd/deck/static/script.js
Outdated
if (!repo || repo === build.spec.refs.repo) { | ||
opts.jobs[build.spec.job] = true; | ||
if (build.spec.type === "presubmit") { | ||
opts.authors[build.spec.refs.pulls[0]['author']] = true; |
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.
is there any case that build.spec.refs.pulls can be null
or undefined
?
prow/cmd/deck/static/script.js
Outdated
build.spec.refs = prop; | ||
} | ||
|
||
if (!build.spec.refs.hasOwnProperty("pulls")) { |
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.
is there any case that build.spec.refs
inherit pulls
? if not we can change the condition to !build.spec.refs.pulls
prow/cmd/deck/static/script.js
Outdated
] | ||
} | ||
|
||
if ( Object.keys(build.spec.refs).length == 0){ |
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.
this should be explicitly periodic
type job as we expect postsubmit
presubmit
and batch
to have refs
; otherwise, revision cells will be filled with broken links.
If postsubmit
, presubmit
or batch
does not have refs
, should we consider to drop it?
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.
I am inclined to say just drop them but if we don't do that today I don't consider it important fixing here.
Looks OK overall to me. There have been some concerns raised by @rmmh and @BenTheElder in the past wrt the size of prowjobs.js. Maybe we can pass a url parameter that would drop pod specs from the response? |
Opened #7386 |
prow/cmd/deck/static/script.js
Outdated
opts.authors[build.author] = true; | ||
opts.pulls[build.number] = true; | ||
opts.states[build.state] = true; | ||
for (var i = 0; i < allBuilds.items.length; i++) { |
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.
Since we're using ES6 now: for (const build of allBuilds.items) {
prow/cmd/deck/static/script.js
Outdated
opts.pulls[build.number] = true; | ||
opts.states[build.state] = true; | ||
for (var i = 0; i < allBuilds.items.length; i++) { | ||
var build = allBuilds.items[i]; |
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.
const spec = build.spec;
, to make the rest shorter?
prow/cmd/deck/static/script.js
Outdated
opts.jobs[build.spec.job] = true; | ||
if (build.spec.type === "presubmit") { | ||
opts.authors[build.spec.refs.pulls[0]['author']] = true; | ||
opts.pulls[build.spec.refs.pulls[0]['number']] = true; |
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.
pulls[0].number
prow/cmd/deck/static/script.js
Outdated
@@ -353,7 +353,11 @@ function equalSelected(sel, t) { | |||
} | |||
|
|||
function groupKey(build) { | |||
return build.repo + " " + build.number + " " + build.refs; | |||
return build.spec.refs.org + "/" + |
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.
This won't do the right grouping for batch jobs. Try this:
const refs = build.spec.refs;
const pulls = refs.pulls.map(r => r.number + ':' + r.sha).join(',');
return `${refs.repo} ${refs.base_ref}:${refs.base_sha},${pulls}`;
completionMoment = new moment(completionTime), | ||
d = moment.duration(completionMoment.diff(startMoment)); | ||
|
||
return d.hours() + "h" + d.minutes() + "m" + d.seconds() + "s"; |
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.
Yeah, see moment/moment#1048.
This is wrong for jobs that take too long, and it will look weird to have a bunch of 0h jobs.
var out = d.seconds() + 's';
if (d.asHours() >= 1)
out = Math.floor(d.asHours()) + 'h' + d.minutes() + 'm' + out;
else if (d.minutes() >= 1)
out = d.minutes() + 'm' + out;
return out;
prow/cmd/deck/static/script.js
Outdated
var build = allBuilds.items[i]; | ||
|
||
// assign default values | ||
var prop = { |
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.
I would skip this, and instead change the one case that uses build.spec.refs to skip if build.spec.refs is empty.
@@ -26,16 +26,16 @@ function optionsForRepo(repo) { | |||
states: {}, | |||
}; |
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.
Why not do an initialization pass to set build.author
and build.number
, and avoid the construct of build.spec.refs.pulls[0]
elsewhere?
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.
This should still be done-- getting the hnumber out should be simpler.
d4d8937
to
5e014da
Compare
5e014da
to
9f52ad9
Compare
@katerinapat is this ready for another round of reviews? |
When we get closer to merge, please rebase your branch on top of master instead of merging. |
@Kargakis. I pushed 2 more commits. Added the param I'll refactor the duration so it won't display all these 0h. Although in this PR I didn't include any other refactoring or changing to ES6. Main goal is to refactor the script to support the new response without brake anything. I'll be more happy to refactor the whole spaghetti code in a future PR |
Please address comments and reopen! |
The PR is mainly refactoring of
script.js
in order to use/prowjobs.js
.The only addition is the calculation of the job's duration which it is not included in the new response.
Ref #5216