Skip to content
Merged
Show file tree
Hide file tree
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
15 changes: 0 additions & 15 deletions src/api/v1/repoBranches.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Debug from 'debug'
import { Response } from 'express'
import { OpenApiRequestExt } from 'src/otomi-models'

const debug = Debug('otomi:api:v2:repoBranches')

/**
* GET /v2/teams/{teamId}/coderepos/{codeRepositoryName}/branches
* Get repository branches
*/
export const getRepoBranches = async (req: OpenApiRequestExt, res: Response): Promise<void> => {
debug('getRepoBranches', req.params)

const { teamId, codeRepositoryName } = req.params as {
teamId: string
codeRepositoryName: string
}

const branches = await req.otomi.getRepoBranches(codeRepositoryName, teamId)

res.json(branches)
}
26 changes: 12 additions & 14 deletions src/openapi/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2696,23 +2696,15 @@ paths:
schema:
$ref: '#/components/schemas/SettingsInfo'

/v1/repoBranches:
/v2/teams/{teamId}/coderepos/{codeRepositoryName}/branches:
parameters:
- $ref: '#/components/parameters/teamParams'
- $ref: '#/components/parameters/codeRepoParams'
get:
operationId: getRepoBranches
x-eov-operation-handler: v1/repoBranches
x-eov-operation-handler: v2/teams/{teamId}/coderepos/{codeRepositoryName}/branches
description: Get repo branches from the git providers.
x-aclSchema: RepoBranches
parameters:
- name: codeRepoName
in: query
description: Name of the code repository
schema:
type: string
- name: teamId
in: query
description: Id of the team
schema:
type: string
x-aclSchema: CodeRepo
responses:
'200':
description: The request is successful.
Expand All @@ -2722,6 +2714,12 @@ paths:
type: array
items:
type: string
'400':
$ref: '#/components/responses/BadRequest'
'403':
$ref: '#/components/responses/Forbidden'
'404':
$ref: '#/components/responses/NotFound'

/v1/testRepoConnect:
get:
Expand Down
17 changes: 11 additions & 6 deletions src/otomi-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1465,13 +1465,16 @@ export default class OtomiStack {

async getRepoBranches(codeRepoName: string, teamId: string): Promise<string[]> {
if (!codeRepoName) return ['HEAD']
const coderepo = this.getCodeRepo(teamId, codeRepoName)
const { repositoryUrl, secret: secretName } = coderepo

const coderepo = this.getAplCodeRepo(teamId, codeRepoName)
const { repositoryUrl, secret: secretName } = coderepo.spec

const { cluster } = await this.getSettings(['cluster'])

try {
let sshPrivateKey = '',
username = '',
accessToken = ''
let sshPrivateKey = ''
let username = ''
let accessToken = ''

if (secretName) {
const secret = await getSecretValues(secretName, `team-${teamId}`)
Expand All @@ -1489,7 +1492,9 @@ export default class OtomiStack {

if (!repoUrl) return ['HEAD']

if (isPrivate) return await getPrivateRepoBranches(repoUrl, sshPrivateKey, username, accessToken)
if (isPrivate) {
return await getPrivateRepoBranches(repoUrl, sshPrivateKey, username, accessToken)
}

return await getPublicRepoBranches(repoUrl)
} catch (error) {
Expand Down