mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-13 21:53:43 +01:00
GitLab Synchronization: add gitlabUrl to ExpressLocals; use settings.gitlabSync instead of env vars
This commit is contained in:
@@ -424,7 +424,8 @@ export default async function (webRouter, privateApiRouter, publicApiRouter) {
|
|||||||
cioSiteId: Settings.analytics?.cio?.siteId,
|
cioSiteId: Settings.analytics?.cio?.siteId,
|
||||||
linkedInInsightsPartnerId: Settings.analytics?.linkedIn?.partnerId,
|
linkedInInsightsPartnerId: Settings.analytics?.linkedIn?.partnerId,
|
||||||
githubSyncEnabled: !!Settings.githubSync?.clientID && !!Settings.githubSync?.clientSecret,
|
githubSyncEnabled: !!Settings.githubSync?.clientID && !!Settings.githubSync?.clientSecret,
|
||||||
gitlabSyncEnabled: !!Settings.gitlabSync?.clientID && !!Settings.gitlabSync?.clientSecret,
|
gitlabSyncEnabled: !!Settings.gitlabSync,
|
||||||
|
gitlabUrl: Settings.gitlabSync?.url,
|
||||||
zoteroEnabled: !!Settings.zotero?.clientKey && !!Settings.zotero?.clientSecret,
|
zoteroEnabled: !!Settings.zotero?.clientKey && !!Settings.zotero?.clientSecret,
|
||||||
enablePandocConversions: Settings.enablePandocConversions,
|
enablePandocConversions: Settings.enablePandocConversions,
|
||||||
mixpanelLabsToken:
|
mixpanelLabsToken:
|
||||||
|
|||||||
@@ -21,16 +21,16 @@ import {
|
|||||||
AlreadyExistsError,
|
AlreadyExistsError,
|
||||||
} from './GitSyncErrors.mjs'
|
} from './GitSyncErrors.mjs'
|
||||||
|
|
||||||
const GITLAB_URL = process.env.GITLAB_SYNC_URL
|
const GITLAB_URL = Settings.gitlabSync?.url
|
||||||
const GITLAB_API_BASE = `${GITLAB_URL}/api/v4`
|
const GITLAB_API_BASE = `${GITLAB_URL}/api/v4`
|
||||||
const GITLAB_DEFAULT_BRANCH = process.env.GITLAB_DEFAULT_BRANCH || 'main'
|
const GITLAB_DEFAULT_BRANCH = Settings.gitlabSync?.defaultBranch
|
||||||
const MAX_PER_PAGE = 100
|
const MAX_PER_PAGE = 100
|
||||||
|
|
||||||
const REQUEST_TIMEOUT_MS = 60 * 1000
|
const REQUEST_TIMEOUT_MS = 60 * 1000
|
||||||
const REQUEST_LONG_TIMEOUT_MS = 600 * 1000
|
const REQUEST_LONG_TIMEOUT_MS = 600 * 1000
|
||||||
|
|
||||||
const MERGE_REQUEST_POLL_INTERVAL_MS = process.env.GITLAB_MERGE_REQUEST_POLL_INTERVAL_MS || 1000
|
const MERGE_REQUEST_POLL_INTERVAL_MS = Settings.gitlabSync?.mergeRequestPollInterval
|
||||||
const MERGE_REQUEST_TIMEOUT_MS = process.env.GITLAB_MERGE_REQUEST_TIMEOUT_MS || 60_000
|
const MERGE_REQUEST_TIMEOUT_MS = Settings.gitlabSync?.mergeRequestTimeout
|
||||||
|
|
||||||
const mergeRequestPendingStates = new Set([
|
const mergeRequestPendingStates = new Set([
|
||||||
'unchecked',
|
'unchecked',
|
||||||
@@ -639,4 +639,4 @@ export default {
|
|||||||
mergeBranch,
|
mergeBranch,
|
||||||
compareCommits,
|
compareCommits,
|
||||||
getRepoZipball,
|
getRepoZipball,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,20 @@ if (process.env.GITLAB_SYNC_ENABLED?.toLowerCase() === 'true') {
|
|||||||
logger.debug({}, 'Enabling GitLab Sync module')
|
logger.debug({}, 'Enabling GitLab Sync module')
|
||||||
|
|
||||||
// The GITLAB_URL variable has to be set for this module to work, otherwise the module will not be enabled
|
// The GITLAB_URL variable has to be set for this module to work, otherwise the module will not be enabled
|
||||||
if (process.env.GITLAB_SYNC_URL === undefined || process.env.GITLAB_SYNC_URL === '') {
|
if (!process.env.GITLAB_SYNC_URL || !process.env.GITLAB_SYNC_CLIENT_ID || !process.env.GITLAB_SYNC_CLIENT_SECRET) {
|
||||||
logger.warn({}, 'GitLab Sync module is enabled but GITLAB_SYNC_URL is not set, stopping module initialization')
|
logger.warn({}, 'GitLab Sync module is enabled but not all mandatory envirionment variables are set, stopping module initialization')
|
||||||
} else {
|
} else {
|
||||||
|
const siteUrl = Settings.siteUrl.replace(/\/+$/, '') || 'http://localhost'
|
||||||
|
Settings.gitlabSync = {
|
||||||
|
url: process.env.GITLAB_SYNC_URL.replace(/\/+$/, ''),
|
||||||
|
clientID: process.env.GITLAB_SYNC_CLIENT_ID,
|
||||||
|
clientSecret: process.env.GITLAB_SYNC_CLIENT_SECRET,
|
||||||
|
callbackURL: `${siteUrl}/user/gitlab-sync/oauth2/callback`,
|
||||||
|
defaultBranch: process.env.GITLAB_DEFAULT_BRANCH || 'main',
|
||||||
|
mergeRequestPollInterval: process.env.GITLAB_MERGE_REQUEST_POLL_INTERVAL_MS || 1000,
|
||||||
|
mergeRequestTimeout: process.env.GITLAB_MERGE_REQUEST_TIMEOUT_MS || 60_000,
|
||||||
|
}
|
||||||
|
|
||||||
const [{ default: GitLabSyncRouter },
|
const [{ default: GitLabSyncRouter },
|
||||||
{ default: SyncStateManager },
|
{ default: SyncStateManager },
|
||||||
{ default: TokenManager }
|
{ default: TokenManager }
|
||||||
@@ -20,13 +31,6 @@ if (process.env.GITLAB_SYNC_ENABLED?.toLowerCase() === 'true') {
|
|||||||
import('./app/src/TokenManager.mjs'),
|
import('./app/src/TokenManager.mjs'),
|
||||||
])
|
])
|
||||||
|
|
||||||
const siteUrl = Settings.siteUrl.replace(/\/+$/, '') || 'http://localhost'
|
|
||||||
Settings.gitlabSync = {
|
|
||||||
clientID: process.env.GITLAB_SYNC_CLIENT_ID,
|
|
||||||
clientSecret: process.env.GITLAB_SYNC_CLIENT_SECRET,
|
|
||||||
callbackURL: `${siteUrl}/user/gitlab-sync/oauth2/callback`,
|
|
||||||
},
|
|
||||||
|
|
||||||
// Delete project sync state from mongo (hook 'projectExpired')
|
// Delete project sync state from mongo (hook 'projectExpired')
|
||||||
Modules.hooks.attach('projectExpired', async projectId => {
|
Modules.hooks.attach('projectExpired', async projectId => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user