Commit 125b30a1 authored by Jose Vargas's avatar Jose Vargas

Change query to get the latest SHA in the pipeline editor

This fixes the editor not working with branches as the
previous query would return empty for merged results
among other scenarios
parent ca17296d
query getLatestCommitSha($projectPath: ID!, $ref: String) {
project(fullPath: $projectPath) {
pipelines(ref: $ref) {
nodes {
id
sha
path
commitPath
repository {
tree(ref: $ref) {
lastCommit {
sha
}
}
}
}
......
......@@ -164,22 +164,8 @@ export default {
};
},
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) {
this.$apollo.queries.commitSha.startPolling(COMMIT_SHA_POLL_INTERVAL);
return this.commitSha;
......
......@@ -159,15 +159,12 @@ export const mergeUnwrappedCiConfig = (mergedConfig) => {
export const mockCommitShaResults = {
data: {
project: {
pipelines: {
nodes: [
{
id: 'gid://gitlab/Ci::Pipeline/1',
repository: {
tree: {
lastCommit: {
sha: mockCommitSha,
path: `/${mockProjectFullPath}/-/pipelines/488`,
commitPath: `/${mockProjectFullPath}/-/commit/d0d56d363d8a3f67a8ab9fc00207d468f30032ca`,
},
],
},
},
},
},
......@@ -176,21 +173,12 @@ export const mockCommitShaResults = {
export const mockNewCommitShaResults = {
data: {
project: {
pipelines: {
nodes: [
{
id: 'gid://gitlab/Ci::Pipeline/2',
repository: {
tree: {
lastCommit: {
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 = {
export const mockEmptyCommitShaResults = {
data: {
project: {
pipelines: {
nodes: [],
repository: {
tree: {
lastCommit: {
sha: '',
},
},
},
},
},
......
......@@ -283,19 +283,6 @@ describe('Pipeline editor app component', () => {
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 () => {
jest
.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