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

fix: First PR reload #1298

Merged
merged 5 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 46 additions & 21 deletions app/components/pipeline/workflow/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { getDisplayJobNameLength, getWorkflowGraph } from './util';
const PIPELINE_EVENT = 'pipeline';
const PR_EVENT = 'pr';
const BUILD_QUEUE_NAME = 'graph';
const RELOAD_ID = 'pipeline';
const LATEST_COMMIT_EVENT_QUEUE_NAME = 'latestCommitEvent';
const OPEN_PRS_QUEUE_NAME = 'openPrs';

export default class PipelineWorkflowComponent extends Component {
@service router;
Expand Down Expand Up @@ -59,6 +60,7 @@ export default class PipelineWorkflowComponent extends Component {
super(...arguments);

const { pipeline } = this.args;
const pipelineId = pipeline.id;

this.pipeline = pipeline;
this.userSettings = this.args.userSettings;
Expand All @@ -68,31 +70,54 @@ export default class PipelineWorkflowComponent extends Component {
: PR_EVENT;

if (this.eventType === PIPELINE_EVENT) {
this.dataReloadId = this.workflowDataReload.start(pipeline.id, false);
this.dataReloadId = this.workflowDataReload.start(pipelineId, false);
} else {
this.dataReloadId = this.workflowDataReload.start(pipeline.id, true);
this.dataReloadId = this.workflowDataReload.start(pipelineId, true);
}

if (this.args.noEvents) {
this.workflowDataReload.registerLatestCommitEventCallback(
BUILD_QUEUE_NAME,
RELOAD_ID,
latestCommitEvent => {
if (latestCommitEvent) {
this.workflowDataReload.removeLatestCommitEventCallback(
BUILD_QUEUE_NAME,
RELOAD_ID
);

const transition = this.router.replaceWith(
'v2.pipeline.events.show',
latestCommitEvent.id
);

transition.data = { latestEvent: latestCommitEvent };
if (this.eventType === PR_EVENT) {
this.workflowDataReload.registerOpenPrsCallback(
OPEN_PRS_QUEUE_NAME,
pipelineId,
openPrs => {
if (openPrs.length > 0) {
this.workflowDataReload.removeOpenPrsCallback(
OPEN_PRS_QUEUE_NAME,
pipelineId
);
const transition = this.router.replaceWith(
'v2.pipeline.pulls.show',
openPrs[0]
);

transition.data = {
prNums: openPrs
};
}
}
}
);
);
} else {
this.workflowDataReload.registerLatestCommitEventCallback(
LATEST_COMMIT_EVENT_QUEUE_NAME,
pipelineId,
latestCommitEvent => {
if (latestCommitEvent) {
this.workflowDataReload.removeLatestCommitEventCallback(
LATEST_COMMIT_EVENT_QUEUE_NAME,
pipelineId
);

const transition = this.router.replaceWith(
'v2.pipeline.events.show',
latestCommitEvent.id
);

transition.data = { latestEvent: latestCommitEvent };
}
}
);
}
minghay marked this conversation as resolved.
Show resolved Hide resolved
} else {
this.jobs = this.args.jobs;
this.stages = this.args.stages;
Expand Down
8 changes: 5 additions & 3 deletions app/v2/pipeline/pulls/show/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ export default class V2PipelinePullsShowRoute extends Route {
}
};

async model(params) {
async model(params, transition) {
const model = this.modelFor('v2.pipeline.pulls');
const { pipeline, pullRequestJobs } = model;
const { pipeline } = model;
const pipelineId = pipeline.id;
const prNums = getPrNumbers(pullRequestJobs);
const prNums = transition.data.prNums
? new Set(transition.data.prNums)
: getPrNumbers(model.pullRequestJobs);
const prNum = parseInt(params.pull_request_number, 10);
const { sha } = params;

Expand Down
8 changes: 8 additions & 0 deletions app/workflow-data-reload/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ export default class WorkflowDataReloadService extends Service {
return this.latestCommitEventReloader.getLatestCommitEvent();
}

registerOpenPrsCallback(queueName, id, callback) {
this.openPrsReloader.registerCallback(queueName, id, callback);
}

removeOpenPrsCallback(queueName, id) {
this.openPrsReloader.removeCallback(queueName, id);
}

getPrNums() {
return this.openPrsReloader.getPrNums();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ module('Integration | Component | pipeline/workflow', function (hooks) {

test('it renders for pipeline with no PRs', async function (assert) {
const router = this.owner.lookup('service:router');
const shuttle = this.owner.lookup('service:shuttle');
const workflowDataReload = this.owner.lookup(
'service:workflow-data-reload'
);

sinon.stub(router, 'currentRouteName').value('pulls');
sinon.stub(shuttle, 'fetchFromApi').resolves([]);
sinon.stub(workflowDataReload, 'start').callsFake(() => {});

this.setProperties({
Expand Down