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

gitlab hosting connector with good current job id return #1602

Closed
wants to merge 2 commits into from
Closed
Changes from all 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
41 changes: 31 additions & 10 deletions src/ts/plugins/server/GitlabHostingConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ export default class GitlabHostingConnector extends GitlabConnector implements H
// Update the job status
if(status === JobStatus.SUCCESS) {
/* Squash and tag the commits */
const succes = await this.createTag(session, websiteId, job, { startJob, jobSuccess, jobError })
if(!succes) {
const successTag = await this.createTag(session, websiteId, job, { startJob, jobSuccess, jobError })
if(successTag === 'failed') {
// jobError will have been called in createTag
return
}
Expand All @@ -100,7 +100,7 @@ export default class GitlabHostingConnector extends GitlabConnector implements H
job.logs[0].push(`Page URL: ${pageUrl}`)
job.message = 'Getting the deployment logs URL...'
job.logs[0].push(job.message)
const gitlabJobLogsUrl = await this.getGitlabJobLogsUrl(session, websiteId, adminUrl)
const gitlabJobLogsUrl = await this.getGitlabJobLogsUrl(session, websiteId, job, { startJob, jobSuccess, jobError }, adminUrl, successTag)
job.logs[0].push(`Deployment logs URL: ${gitlabJobLogsUrl}`)
const message = `
<p><a href="${gitlabUrl}" target="_blank">Your website is now live here</a>.</p>
Expand Down Expand Up @@ -146,12 +146,32 @@ export default class GitlabHostingConnector extends GitlabConnector implements H
return `${projectUrl}/pages`
}

async getGitlabJobLogsUrl(session: GitlabSession, websiteId: WebsiteId, projectUrl: string): Promise<string> {
const jobs = await this.callApi(session, `api/v4/projects/${websiteId}/jobs`, 'GET')
return `${projectUrl}/-/jobs/${jobs[0].id}`
async getGitlabJobLogsUrl(session: GitlabSession, websiteId: WebsiteId, job: PublicationJobData, { startJob, jobSuccess, jobError }: JobManager, projectUrl: string, tag): Promise<string> {
let jobs = await this.callApi(session, `api/v4/projects/${websiteId}/jobs`, 'GET')
// waiting for the job corresponding to the current tag
let i = 0
setTimeout (() => {
while (jobs[0].ref !== tag && i<20) {
jobs = this.callApi(session, `api/v4/projects/${websiteId}/jobs`, 'GET')
i++
}
}, 100)

// return jobs page or job id page following timer (avoiding infinite loop)
if ( i===20 ) {
console.error('unable to get job id, waiting for ', i+1, ' cycles')
jobError(job.jobId, 'Failed to get job id')
job.message = 'Unable to get job id'
job.logs[0].push(job.message)
return `${projectUrl}/-/jobs/`
}
else {
console.log('job id obtained in ', i+1, ' cycles')
return `${projectUrl}/-/jobs/${jobs[0].id}`
}
}

async createTag(session: GitlabSession, websiteId: WebsiteId, job: JobData, { startJob, jobSuccess, jobError }: JobManager): Promise<boolean> {
async createTag(session: GitlabSession, websiteId: WebsiteId, job: JobData, { startJob, jobSuccess, jobError }: JobManager): Promise<string> {
const projectId = websiteId // Assuming websiteId corresponds to GitLab project ID

// Fetch the latest tag and determine the new tag
Expand All @@ -166,7 +186,7 @@ export default class GitlabHostingConnector extends GitlabConnector implements H
} catch (error) {
console.error('Error during fetching latest tag:', error.message)
jobError(job.jobId, `Failed to fetch latest tag: ${error.message}`)
return false
return 'Failed'
}

// Create a new tag
Expand All @@ -180,9 +200,10 @@ export default class GitlabHostingConnector extends GitlabConnector implements H
} catch (error) {
console.error('Error during creating new tag:', error.message)
jobError(job.jobId, `Failed to create new tag: ${error.message}`)
return false
return 'Failed'
}
return true
// return new tag
return newTag
}

}
Loading