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 policy error fix #1605

Merged
merged 12 commits into from
Jun 19, 2024
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@
"@silexlabs/grapesjs-loading": "1.0.9",
"@silexlabs/grapesjs-notifications": "^0.0.8",
"@silexlabs/grapesjs-storage-rate-limit": "^1.0.8",
"@silexlabs/grapesjs-symbols": "1.0.41",
"@silexlabs/grapesjs-symbols": "1.0.40",
SuperDelphi marked this conversation as resolved.
Show resolved Hide resolved
"@silexlabs/grapesjs-ui-suggest-classes": "1.0.23",
"@silexlabs/grapesjs-keymaps-dialog": "^1.0.15",
"@silexlabs/grapesjs-keymaps-dialog": "^1.0.0",
"@silexlabs/silex-plugins": "1.0.10",
"@types/archiver": "^6.0.2",
"adm-zip": "0.5.12",
Expand Down Expand Up @@ -139,7 +139,7 @@
"html-minifier": "^4.0.0",
"lit-html": "3.1.2",
"mkdirp": "3.0.1",
"node_modules-path": "2.0.8",
"node_modules-path": "2.0.7",
"node-fetch": "2.6.9",
"normalize.css": "8.0.1",
"object-path": "0.11.8",
Expand Down
33 changes: 33 additions & 0 deletions src/css/grapesjs-plugins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,40 @@
}

// publication-ui
@keyframes pub-blink {
from {
opacity: 0.25;
}
to {
opacity: 1;
}
}

#publish-dialog {
.notice {
margin: 10px 0;
background-color: rgba(255, 166, 0, 0.2);
border-radius: 5px;
padding: 10px;
}

progress {
width: 100%;
border-radius: 50px;
border: none;
height: 5px;
animation: pub-blink 0.33s infinite alternate;
background-color: $tertiaryColor;
}

progress::-webkit-progress-bar {
background-color: $tertiaryColor;
}

progress::-moz-progress-bar {
background-color: $tertiaryColor;
}

header {
display: flex;
align-items: center;
Expand Down
11 changes: 8 additions & 3 deletions src/ts/plugins/server/GitlabConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ export default class GitlabConnector implements StorageConnector {
return encodeURIComponent(join(this.options.assetsFolder, path))
}

isUsingOfficialInstance(): boolean {
const gitlabDomainRegexp = /(^|\b)(gitlab\.com)($|\b)/
return gitlabDomainRegexp.test(this.options.domain)
}

async createFile(session: GitlabSession, websiteId: WebsiteId, path: string, content: string, isBase64 = false): Promise<void> {
// Remove leading slash
const safePath = path.replace(/^\//, '')
Expand Down Expand Up @@ -292,7 +297,7 @@ export default class GitlabConnector implements StorageConnector {
const headers = {
'Content-Type': 'application/json',
}
if(method === 'GET' && body) {
if (method === 'GET' && body) {
console.error('Gitlab API error (4) - GET request with body', {url, method, body, params})
}
// With or without body
Expand All @@ -311,9 +316,9 @@ export default class GitlabConnector implements StorageConnector {
throw new ApiError(`Gitlab API error (0): ${e.message} ${e.code} ${e.name} ${e.type}`, 500)
}
let json: { message: string, error: string } | any
// Handle the case when the server returns an non-JSON response (e.g. 400 Bad Request)
// Handle the case when the server returns a non-JSON response (e.g. 400 Bad Request)
const text = await response.text()
if(!response.ok) {
if (!response.ok) {
if (text.includes('A file with this name doesn\'t exist')) {
throw new ApiError('Gitlab API error (5): Not Found', 404)
} else if (response.status === 401 && this.getSessionToken(session).token?.refresh_token) {
Expand Down
20 changes: 19 additions & 1 deletion src/ts/plugins/server/GitlabHostingConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,23 @@ export default class GitlabHostingConnector extends GitlabConnector implements H
job.message = 'Getting the deployment logs URL...'
job.logs[0].push(job.message)
const gitlabJobLogsUrl = await this.getGitlabJobLogsUrl(session, websiteId, adminUrl)

// Because of the GitLab policy, this can be undefined (and we suggest the user to verify their account)
if (!gitlabJobLogsUrl) {
let errorMessage = 'Could not retrieve the deployment logs URL.'

if (this.isUsingOfficialInstance()) {
const verifyURL = 'https://gitlab.com/-/identity_verification'
errorMessage +=
`<div class="notice">
If your GitLab account is recent, you may need to verify it <a href="${verifyURL}">here</a>
in order to be able to use pipelines (this is GitLab's policy, not Silex's).
</div>`
}

throw new Error(errorMessage)
}

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,8 +163,9 @@ export default class GitlabHostingConnector extends GitlabConnector implements H
return `${projectUrl}/pages`
}

async getGitlabJobLogsUrl(session: GitlabSession, websiteId: WebsiteId, projectUrl: string): Promise<string> {
async getGitlabJobLogsUrl(session: GitlabSession, websiteId: WebsiteId, projectUrl: string): Promise<string | undefined> {
const jobs = await this.callApi(session, `api/v4/projects/${websiteId}/jobs`, 'GET')
if (!jobs.length) return undefined
SuperDelphi marked this conversation as resolved.
Show resolved Hide resolved
return `${projectUrl}/-/jobs/${jobs[0].id}`
}

Expand Down
Loading