Commit ff0aa99f authored by Simon Knox's avatar Simon Knox

Merge branch 'jivanvl-fix-pipeline-editor-missing-sha' into 'master'

Change query to get the latest SHA in the pipeline editor

See merge request gitlab-org/gitlab!70077
parents 354c37c4 125b30a1
query getLatestCommitSha($projectPath: ID!, $ref: String) { query getLatestCommitSha($projectPath: ID!, $ref: String) {
project(fullPath: $projectPath) { project(fullPath: $projectPath) {
pipelines(ref: $ref) { repository {
nodes { tree(ref: $ref) {
id lastCommit {
sha sha
path }
commitPath
} }
} }
} }
......
...@@ -164,22 +164,8 @@ export default { ...@@ -164,22 +164,8 @@ export default {
}; };
}, },
update(data) { update(data) {
const pipelineNodes = data.project?.pipelines?.nodes ?? []; const latestCommitSha = data.project?.repository?.tree?.lastCommit?.sha;
// it's possible to query for the commit sha too early after an update
// (e.g. after committing a new branch, we might query for the commit sha
// but the pipeline nodes are still empty).
// in this case, we start polling until we get a commit sha.
if (pipelineNodes.length === 0) {
if (![EDITOR_APP_STATUS_LOADING, EDITOR_APP_STATUS_EMPTY].includes(this.appStatus)) {
this.$apollo.queries.commitSha.startPolling(COMMIT_SHA_POLL_INTERVAL);
return this.commitSha;
}
return '';
}
const latestCommitSha = pipelineNodes[0].sha;
if (this.isFetchingCommitSha && latestCommitSha === this.commitSha) { if (this.isFetchingCommitSha && latestCommitSha === this.commitSha) {
this.$apollo.queries.commitSha.startPolling(COMMIT_SHA_POLL_INTERVAL); this.$apollo.queries.commitSha.startPolling(COMMIT_SHA_POLL_INTERVAL);
return this.commitSha; return this.commitSha;
......
...@@ -159,15 +159,12 @@ export const mergeUnwrappedCiConfig = (mergedConfig) => { ...@@ -159,15 +159,12 @@ export const mergeUnwrappedCiConfig = (mergedConfig) => {
export const mockCommitShaResults = { export const mockCommitShaResults = {
data: { data: {
project: { project: {
pipelines: { repository: {
nodes: [ tree: {
{ lastCommit: {
id: 'gid://gitlab/Ci::Pipeline/1',
sha: mockCommitSha, sha: mockCommitSha,
path: `/${mockProjectFullPath}/-/pipelines/488`,
commitPath: `/${mockProjectFullPath}/-/commit/d0d56d363d8a3f67a8ab9fc00207d468f30032ca`,
}, },
], },
}, },
}, },
}, },
...@@ -176,21 +173,12 @@ export const mockCommitShaResults = { ...@@ -176,21 +173,12 @@ export const mockCommitShaResults = {
export const mockNewCommitShaResults = { export const mockNewCommitShaResults = {
data: { data: {
project: { project: {
pipelines: { repository: {
nodes: [ tree: {
{ lastCommit: {
id: 'gid://gitlab/Ci::Pipeline/2',
sha: 'eeff1122', sha: 'eeff1122',
path: `/${mockProjectFullPath}/-/pipelines/489`,
commitPath: `/${mockProjectFullPath}/-/commit/bb1abcfe3d8a3f67a8ab9fc00207d468f3022bee`,
}, },
{ },
id: 'gid://gitlab/Ci::Pipeline/1',
sha: mockCommitSha,
path: `/${mockProjectFullPath}/-/pipelines/488`,
commitPath: `/${mockProjectFullPath}/-/commit/d0d56d363d8a3f67a8ab9fc00207d468f30032ca`,
},
],
}, },
}, },
}, },
...@@ -199,8 +187,12 @@ export const mockNewCommitShaResults = { ...@@ -199,8 +187,12 @@ export const mockNewCommitShaResults = {
export const mockEmptyCommitShaResults = { export const mockEmptyCommitShaResults = {
data: { data: {
project: { project: {
pipelines: { repository: {
nodes: [], tree: {
lastCommit: {
sha: '',
},
},
}, },
}, },
}, },
......
...@@ -283,19 +283,6 @@ describe('Pipeline editor app component', () => { ...@@ -283,19 +283,6 @@ describe('Pipeline editor app component', () => {
expect(window.scrollTo).toHaveBeenCalledWith({ top: 0, behavior: 'smooth' }); expect(window.scrollTo).toHaveBeenCalledWith({ top: 0, behavior: 'smooth' });
}); });
it('polls for commit sha while pipeline data is not yet available for newly committed branch', async () => {
jest
.spyOn(wrapper.vm.$apollo.queries.commitSha, 'startPolling')
.mockImplementation(jest.fn());
// simulate updating current branch (which triggers commitSha refetch)
// while pipeline data is not yet available
mockLatestCommitShaQuery.mockResolvedValue(mockEmptyCommitShaResults);
await wrapper.vm.$apollo.queries.commitSha.refetch();
expect(wrapper.vm.$apollo.queries.commitSha.startPolling).toHaveBeenCalledTimes(1);
});
it('polls for commit sha while pipeline data is not yet available for current branch', async () => { it('polls for commit sha while pipeline data is not yet available for current branch', async () => {
jest jest
.spyOn(wrapper.vm.$apollo.queries.commitSha, 'startPolling') .spyOn(wrapper.vm.$apollo.queries.commitSha, 'startPolling')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment