Skip to content

Commit c4adb0e

Browse files
authored
RHTAPBUGS-1327 Add wait for Gitlab repo creation, updates to use new (#173)
version of templates Signed-off-by: Josef Kopriva <[email protected]>
1 parent 8bcb0e8 commit c4adb0e

File tree

6 files changed

+41
-26
lines changed

6 files changed

+41
-26
lines changed

src/apis/git-providers/gitlab.ts

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,43 @@ export class GitLabProvider extends Utils {
2121

2222
// Function to find a repository by name
2323
public async checkIfRepositoryExists(namespace: string, repoName: string): Promise<number> {
24-
try {
25-
const projects = await this.gitlab.Projects.show(`${namespace}/${repoName}`);
26-
console.info(`Repository with name '${repoName}' found in namespace '${namespace}'
27-
created at '${projects.created_at}' url: gitlab.com/${namespace}/${repoName}`);
24+
//RHTAPBUGS-1327: Added wait: it should improve stability of Gitlab test - sometimes request from tests could be faster, than GitLab responses
25+
while (true) {
26+
try {
27+
const projects = await this.gitlab.Projects.show(`${namespace}/${repoName}`);
28+
if (projects) {
29+
console.info(`Repository with name '${repoName}' found in namespace '${namespace}'
30+
created at '${projects.created_at}' url: gitlab.com/${namespace}/${repoName}`);
31+
return projects.id
32+
}
2833

29-
return projects.id
30-
} catch (error) {
31-
console.error(error);
34+
await this.sleep(5000); // Wait 5 seconds before checking again
35+
} catch (error) {
36+
console.info(`Failed to check if repository ${repoName} exists`);
3237

33-
throw new Error(`Failed to check if repository ${repoName} exists`);
38+
}
3439
}
3540
}
3641

3742
/**
3843
* checkIfRepositoryHaveFolder
3944
*/
4045
public async checkIfRepositoryHaveFolder(repositoryID: number, folderPath: string): Promise<boolean> {
41-
const file = await this.gitlab.Repositories.allRepositoryTrees(repositoryID)
46+
//RHTAPBUGS-1327: Added wait: it should improve stability of Gitlab test - sometimes request from tests could be faster, than GitLab responses
47+
while (true) {
48+
try {
49+
const file = await this.gitlab.Repositories.allRepositoryTrees(repositoryID)
50+
if (file) {
51+
return file.some((folder) => {
52+
return folder.path === folderPath && folder.type === 'tree'
53+
})
54+
}
4255

43-
return file.some((folder)=> {
44-
return folder.path === folderPath && folder.type === 'tree'
45-
})
56+
await this.sleep(5000); // Wait 5 seconds before checking again
57+
} catch (error) {
58+
console.info('Error checking for folder creation');
59+
}
60+
}
4661
}
4762

4863
/**

tests/gpts/github/test-config/github_advanced_scenario.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export const githubSoftwareTemplatesAdvancedScenarios = (gptTemplate: string) =>
117117
templateRef: `template:default/${gptTemplate}`,
118118
values: {
119119
branch: 'main',
120-
githubServer: 'github.com',
120+
ghHost: 'github.com',
121121
hostType: 'GitHub',
122122
imageName: quayImageName,
123123
imageOrg: quayImageOrg,
@@ -126,7 +126,7 @@ export const githubSoftwareTemplatesAdvancedScenarios = (gptTemplate: string) =>
126126
namespace: componentRootNamespace,
127127
owner: "user:guest",
128128
repoName: repositoryName,
129-
repoOwner: githubOrganization,
129+
ghOwner: githubOrganization,
130130
ciType: "tekton"
131131
}
132132
};

tests/gpts/github/test-config/github_positive_suite.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export const gitHubBasicGoldenPathTemplateTests = (gptTemplate: string) => {
9595
templateRef: `template:default/${gptTemplate}`,
9696
values: {
9797
branch: 'main',
98-
githubServer: 'github.com',
98+
ghHost: 'github.com',
9999
hostType: 'GitHub',
100100
imageName: quayImageName,
101101
imageOrg: quayImageOrg,
@@ -104,7 +104,7 @@ export const gitHubBasicGoldenPathTemplateTests = (gptTemplate: string) => {
104104
namespace: componentRootNamespace,
105105
owner: "user:guest",
106106
repoName: repositoryName,
107-
repoOwner: githubOrganization,
107+
ghOwner: githubOrganization,
108108
ciType: "tekton"
109109
}
110110
};

tests/gpts/github/test-config/github_suite_jenkins.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ export const gitHubJenkinsBasicGoldenPathTemplateTests = (gptTemplate: string, s
102102
name: repositoryName,
103103
owner: "user:guest",
104104
hostType: 'GitHub',
105-
repoOwner: githubOrganization,
105+
ghOwner: githubOrganization,
106106
repoName: repositoryName,
107107
branch: 'main',
108-
githubServer: 'github.com',
108+
ghHost: 'github.com',
109109
ciType: 'jenkins',
110110
imageRegistry: 'quay.io',
111111
imageOrg: quayImageOrg,

tests/gpts/gitlab/suites-config/gitlab_advanced_suite.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export const gitLabSoftwareTemplatesAdvancedScenarios = (softwareTemplateName: s
106106
templateRef: `template:default/${softwareTemplateName}`,
107107
values: {
108108
branch: 'main',
109-
gitlabServer: 'gitlab.com',
109+
glHost: 'gitlab.com',
110110
hostType: 'GitLab',
111111
imageName: quayImageName,
112112
imageOrg: quayImageOrg,
@@ -115,7 +115,7 @@ export const gitLabSoftwareTemplatesAdvancedScenarios = (softwareTemplateName: s
115115
namespace: componentRootNamespace,
116116
owner: "user:guest",
117117
repoName: repositoryName,
118-
repoOwner: gitLabOrganization,
118+
glOwner: gitLabOrganization,
119119
ciType: "tekton"
120120
}
121121
};
@@ -153,7 +153,7 @@ export const gitLabSoftwareTemplatesAdvancedScenarios = (softwareTemplateName: s
153153

154154
const tektonFolderExists = await gitLabProvider.checkIfRepositoryHaveFolder(gitlabRepositoryID, '.tekton')
155155
expect(tektonFolderExists).toBe(true)
156-
})
156+
}, 120000)
157157

158158
/**
159159
* Verifies if Red Hat Developer Hub created a repository from the specified template in GitLab.
@@ -165,7 +165,7 @@ export const gitLabSoftwareTemplatesAdvancedScenarios = (softwareTemplateName: s
165165

166166
const tektonFolderExists = await gitLabProvider.checkIfRepositoryHaveFolder(gitlabGitopsRepositoryID, '.tekton')
167167
expect(tektonFolderExists).toBe(true)
168-
})
168+
}, 120000)
169169

170170
/**
171171
* Waits for the specified ArgoCD application associated with the DeveloperHub task to be synchronized in the cluster.

tests/gpts/gitlab/suites-config/gitlab_positive_suite.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const gitLabProviderBasicTests = (softwareTemplateName: string) => {
9090
templateRef: `template:default/${softwareTemplateName}`,
9191
values: {
9292
branch: 'main',
93-
gitlabServer: 'gitlab.com',
93+
glHost: 'gitlab.com',
9494
hostType: 'GitLab',
9595
imageName: quayImageName,
9696
imageOrg: quayImageOrg,
@@ -99,7 +99,7 @@ export const gitLabProviderBasicTests = (softwareTemplateName: string) => {
9999
namespace: componentRootNamespace,
100100
owner: "user:guest",
101101
repoName: repositoryName,
102-
repoOwner: gitLabOrganization,
102+
glOwner: gitLabOrganization,
103103
ciType: "tekton"
104104
}
105105
};
@@ -138,7 +138,7 @@ export const gitLabProviderBasicTests = (softwareTemplateName: string) => {
138138

139139
const tektonFolderExists = await gitLabProvider.checkIfRepositoryHaveFolder(gitlabRepositoryID, '.tekton')
140140
expect(tektonFolderExists).toBe(true)
141-
})
141+
}, 120000)
142142

143143
/**
144144
* Verifies if Red Hat Developer Hub created a repository from the specified template in GitHub.
@@ -149,7 +149,7 @@ export const gitLabProviderBasicTests = (softwareTemplateName: string) => {
149149

150150
const tektonFolderExists = await gitLabProvider.checkIfRepositoryHaveFolder(repositoryID, '.tekton')
151151
expect(tektonFolderExists).toBe(true)
152-
})
152+
}, 120000)
153153

154154
/**
155155
* Waits for the specified ArgoCD application associated with the DeveloperHub task to be synchronized in the cluster.

0 commit comments

Comments
 (0)