Skip to content

Commit 52c42af

Browse files
committed
Clean up
1 parent 0568234 commit 52c42af

5 files changed

Lines changed: 43 additions & 249 deletions

File tree

forge/ee/lib/gitops/backends/azure.js

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,7 @@ const execPromised = promisify(exec)
1010

1111
const { encryptValue, decryptValue } = require('../../../../db/utils')
1212

13-
async function cloneRepository (url, branch, workingDir) {
14-
try {
15-
await execPromised(`git clone -b ${branch} --depth 1 --single-branch ${url.toString()} .`, { cwd: workingDir })
16-
} catch (err) {
17-
const output = err.stdout + err.stderr
18-
// Token does not have access to clone the repo
19-
if (/unable to access/.test(output)) {
20-
const result = new Error('Permission denied')
21-
result.code = 'invalid_token'
22-
result.cause = err
23-
throw result
24-
}
25-
// Remote branch does not exist
26-
if (/Could not find remote branch|Remote branch .+ not found/.test(output)) {
27-
const result = new Error('Branch not found')
28-
result.code = 'invalid_branch'
29-
throw result
30-
}
31-
let error
32-
// Fallback - try to extract the 'fatal' line from the output
33-
const m = /fatal: (.*)/.exec(output)
34-
if (m) {
35-
error = new Error('Failed to clone repository: ' + m[1])
36-
} else {
37-
error = new Error('Failed to clone repository')
38-
}
39-
error.cause = err
40-
throw error
41-
}
42-
}
13+
const { cloneRepository } = require('./utils')
4314

4415
module.exports.init = async function (app) {
4516
/**
@@ -65,6 +36,7 @@ module.exports.init = async function (app) {
6536
const url = new URL(repoOptions.url)
6637
url.password = token
6738

39+
// TODO find an azure version
6840
// 2. get user details so we can properly attribute the commit
6941
// let userDetails
7042
// try {
@@ -82,6 +54,7 @@ module.exports.init = async function (app) {
8254
// throw result
8355
// }
8456

57+
// TODO fix these place holders
8558
const userGitName = 'flowfuse' // userDetails.data.login
8659
const userGitEmail = 'flowfuse@example.com' // `${userDetails.data.id}+${userDetails.data.login}@users.noreply.github.com`
8760
const author = `${userGitName} <${userGitEmail}>`.replace(/"/g, '\\"')

forge/ee/lib/gitops/backends/github.js

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,7 @@ const axios = require('axios')
1010

1111
const { encryptValue, decryptValue } = require('../../../../db/utils')
1212

13-
async function cloneRepository (url, branch, workingDir) {
14-
try {
15-
await execPromised(`git clone -b ${branch} --depth 1 --single-branch ${url.toString()} .`, { cwd: workingDir })
16-
} catch (err) {
17-
const output = err.stdout + err.stderr
18-
// Token does not have access to clone the repo
19-
if (/unable to access/.test(output)) {
20-
const result = new Error('Permission denied')
21-
result.code = 'invalid_token'
22-
result.cause = err
23-
throw result
24-
}
25-
// Remote branch does not exist
26-
if (/Could not find remote branch|Remote branch .+ not found/.test(output)) {
27-
const result = new Error('Branch not found')
28-
result.code = 'invalid_branch'
29-
throw result
30-
}
31-
let error
32-
// Fallback - try to extract the 'fatal' line from the output
33-
const m = /fatal: (.*)/.exec(output)
34-
if (m) {
35-
error = new Error('Failed to clone repository: ' + m[1])
36-
} else {
37-
error = new Error('Failed to clone repository')
38-
}
39-
error.cause = err
40-
throw error
41-
}
42-
}
13+
const { cloneRepository } = require('./utils')
4314

4415
module.exports.init = async function (app) {
4516
/**
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const { exec } = require('node:child_process')
2+
const { promisify } = require('node:util')
3+
const execPromised = promisify(exec)
4+
5+
async function cloneRepository (url, branch, workingDir) {
6+
try {
7+
await execPromised(`git clone -b ${branch} --depth 1 --single-branch ${url.toString()} .`, { cwd: workingDir })
8+
} catch (err) {
9+
const output = err.stdout + err.stderr
10+
// Token does not have access to clone the repo
11+
if (/unable to access/.test(output)) {
12+
const result = new Error('Permission denied')
13+
result.code = 'invalid_token'
14+
result.cause = err
15+
throw result
16+
}
17+
// Remote branch does not exist
18+
if (/Could not find remote branch|Remote branch .+ not found/.test(output)) {
19+
const result = new Error('Branch not found')
20+
result.code = 'invalid_branch'
21+
throw result
22+
}
23+
let error
24+
// Fallback - try to extract the 'fatal' line from the output
25+
const m = /fatal: (.*)/.exec(output)
26+
if (m) {
27+
error = new Error('Failed to clone repository: ' + m[1])
28+
} else {
29+
error = new Error('Failed to clone repository')
30+
}
31+
error.cause = err
32+
throw error
33+
}
34+
}
35+
36+
module.exports = {
37+
cloneRepository
38+
}

forge/ee/lib/gitops/index.js

Lines changed: 0 additions & 188 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,7 @@
11
const { exec } = require('node:child_process')
2-
// const { existsSync } = require('node:fs')
3-
// const fs = require('node:fs/promises')
4-
// const os = require('node:os')
5-
// const path = require('node:path')
62
const { promisify } = require('node:util')
73
const execPromised = promisify(exec)
84

9-
// const axios = require('axios')
10-
11-
// const { encryptValue, decryptValue } = require('../../../db/utils')
12-
13-
// async function cloneRepository (url, branch, workingDir) {
14-
// try {
15-
// await execPromised(`git clone -b ${branch} --depth 1 --single-branch ${url.toString()} .`, { cwd: workingDir })
16-
// } catch (err) {
17-
// const output = err.stdout + err.stderr
18-
// // Token does not have access to clone the repo
19-
// if (/unable to access/.test(output)) {
20-
// const result = new Error('Permission denied')
21-
// result.code = 'invalid_token'
22-
// result.cause = err
23-
// throw result
24-
// }
25-
// // Remote branch does not exist
26-
// if (/Could not find remote branch|Remote branch .+ not found/.test(output)) {
27-
// const result = new Error('Branch not found')
28-
// result.code = 'invalid_branch'
29-
// throw result
30-
// }
31-
// let error
32-
// // Fallback - try to extract the 'fatal' line from the output
33-
// const m = /fatal: (.*)/.exec(output)
34-
// if (m) {
35-
// error = new Error('Failed to clone repository: ' + m[1])
36-
// } else {
37-
// error = new Error('Failed to clone repository')
38-
// }
39-
// error.cause = err
40-
// throw error
41-
// }
42-
// }
43-
445
module.exports.init = async function (app) {
456
// Check if git is installed
467
try {
@@ -77,101 +38,6 @@ module.exports.init = async function (app) {
7738
azure.pushToRepository(repoOptions, snapshot, options)
7839
}
7940
}
80-
// async function pushToRepository (repoOptions, snapshot, options) {
81-
// let workingDir
82-
// try {
83-
// const token = repoOptions.token
84-
// const branch = repoOptions.branch || 'main'
85-
// if (!/^https:\/\/github.com/i.test(repoOptions.url)) {
86-
// throw new Error('Only GitHub repositories are supported')
87-
// }
88-
// const url = new URL(repoOptions.url)
89-
// url.username = 'x-access-token'
90-
// url.password = token
91-
92-
// // 2. get user details so we can properly attribute the commit
93-
// let userDetails
94-
// try {
95-
// userDetails = await axios.get('https://api.github.com/user', {
96-
// headers: {
97-
// Accept: 'application/vnd.github+json',
98-
// Authorization: `Bearer ${token}`,
99-
// 'X-GitHub-Api-Version': '2022-11-28'
100-
// }
101-
// })
102-
// } catch (err) {
103-
// const result = new Error('Invalid git token')
104-
// result.code = 'invalid_token'
105-
// result.cause = err
106-
// throw result
107-
// }
108-
109-
// const userGitName = userDetails.data.login
110-
// const userGitEmail = `${userDetails.data.id}+${userDetails.data.login}@users.noreply.github.com`
111-
// const author = `${userGitName} <${userGitEmail}>`.replace(/"/g, '\\"')
112-
// workingDir = await fs.mkdtemp(path.join(os.tmpdir(), 'flowfuse-git-repo-'))
113-
114-
// // 3. clone repo
115-
// await cloneRepository(url, branch, workingDir)
116-
117-
// // 4. set username/email
118-
// await execPromised('git config user.email "no-reply@flowfuse.com"', { cwd: workingDir })
119-
// await execPromised('git config user.name "FlowFuse"', { cwd: workingDir })
120-
// // For local dev - disable gpg signing in case its set in global config
121-
// await execPromised('git config commit.gpgsign false', { cwd: workingDir })
122-
123-
// // 5. export snapshot
124-
// const exportOptions = {
125-
// credentialSecret: repoOptions.credentialSecret,
126-
// components: {
127-
// flows: true,
128-
// credentials: true
129-
// }
130-
// }
131-
// const result = await app.db.controllers.Snapshot.exportSnapshot(snapshot, exportOptions)
132-
// const snapshotExport = app.db.views.ProjectSnapshot.snapshotExport(result)
133-
// if (snapshotExport.settings?.settings?.palette?.npmrc) {
134-
// const enc = encryptValue(repoOptions.credentialSecret, snapshotExport.settings.settings?.palette?.npmrc)
135-
// snapshotExport.settings.settings.palette.npmrc = { $: enc }
136-
// }
137-
// const snapshotFile = path.join(workingDir, repoOptions.path || 'snapshot.json').replace(/"/g, '')
138-
// await fs.writeFile(snapshotFile, JSON.stringify(snapshotExport, null, 4))
139-
140-
// // 6. stage file
141-
// await execPromised(`git add "${snapshotFile}"`, { cwd: workingDir })
142-
143-
// // 7. commit
144-
// await execPromised(`git commit -m "Update snapshot\n\nSnapshot updated by FlowFuse Pipeline '${options.pipeline.name.replace(/"/g, '')}', triggered by ${options.user.username.replace(/"/g, '')}" --author="${author}"`, { cwd: workingDir })
145-
146-
// try {
147-
// // 8. push
148-
// await execPromised('git push', { cwd: workingDir })
149-
// } catch (err) {
150-
// const output = err.stdout + err.stderr
151-
// if (/unable to access/.test(output)) {
152-
// const result = new Error('Permission denied')
153-
// result.code = 'invalid_token'
154-
// result.cause = err
155-
// throw result
156-
// }
157-
// let error
158-
// const m = /fatal: (.*)/.exec(output)
159-
// if (m) {
160-
// error = new Error('Failed to push repository: ' + m[1])
161-
// } else {
162-
// error = Error('Failed to push repository')
163-
// }
164-
// error.cause = err
165-
// throw error
166-
// }
167-
// } finally {
168-
// if (workingDir) {
169-
// try {
170-
// await fs.rm(workingDir, { recursive: true, force: true })
171-
// } catch (err) {}
172-
// }
173-
// }
174-
// }
17541

17642
/**
17743
* Push a snapshot to a git repository
@@ -187,61 +53,7 @@ module.exports.init = async function (app) {
18753
return azure.pullFromRepository(repoOptions)
18854
}
18955
}
190-
// async function pullFromRepository (repoOptions) {
191-
// let workingDir
192-
// try {
193-
// const token = repoOptions.token
194-
// const branch = repoOptions.branch || 'main'
195-
// if (!/^https:\/\/github.com/i.test(repoOptions.url)) {
196-
// throw new Error('Only GitHub repositories are supported')
197-
// }
198-
// const url = new URL(repoOptions.url)
199-
// url.username = 'x-access-token'
200-
// url.password = token
201-
202-
// workingDir = await fs.mkdtemp(path.join(os.tmpdir(), 'flowfuse-git-repo-'))
203-
204-
// // 3. clone repo
205-
// await cloneRepository(url, branch, workingDir)
206-
207-
// const snapshotFile = path.join(workingDir, repoOptions.path || 'snapshot.json').replace(/"/g, '')
208-
209-
// if (!existsSync(snapshotFile)) {
210-
// throw new Error('Snapshot file not found in repository')
211-
// }
21256

213-
// try {
214-
// const snapshotContent = await fs.readFile(snapshotFile, 'utf8')
215-
// const snapshot = JSON.parse(snapshotContent)
216-
// if (snapshot.settings?.env) {
217-
// const keys = Object.keys(snapshot.settings.env)
218-
// keys.forEach((key) => {
219-
// const env = snapshot.settings.env[key]
220-
// if (env.hidden && env.$) {
221-
// // Decrypt the value if it is encrypted
222-
// env.value = decryptValue(repoOptions.credentialSecret, env.$)
223-
// delete env.$
224-
// }
225-
// })
226-
// }
227-
// if (snapshot.settings?.settings?.palette?.npmrc) {
228-
// const npmrc = snapshot.settings.settings.palette.npmrc
229-
// if (typeof npmrc === 'object' && npmrc.$) {
230-
// snapshot.settings.settings.palette.npmrc = decryptValue(repoOptions.credentialSecret, npmrc.$)
231-
// }
232-
// }
233-
// return snapshot
234-
// } catch (err) {
235-
// throw new Error('Failed to read snapshot file: ' + err.message)
236-
// }
237-
// } finally {
238-
// if (workingDir) {
239-
// try {
240-
// await fs.rm(workingDir, { recursive: true, force: true })
241-
// } catch (err) {}
242-
// }
243-
// }
244-
// }
24557
return {
24658
pushToRepository,
24759
pullFromRepository

frontend/src/pages/team/Pipelines/components/TeamPipelineStage.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export default {
6161
case this.isDeviceGroupsStage:
6262
return this.stage.deviceGroups[0]?.name
6363
case this.isGitRepoStage:
64-
return this.stage.gitRepo?.url.replace('https://github.com/', '') + (
64+
return this.stage.gitRepo?.url.replace('https://github.com/', '').replace('https://dev.azure.com/', '') + (
6565
(this.stage.gitRepo?.branch && this.stage.gitRepo?.branch !== 'main' && this.stage.gitRepo?.branch !== 'master')
6666
? `@${this.stage.gitRepo.branch}`
6767
: ''

0 commit comments

Comments
 (0)