Skip to content

Commit

Permalink
feat: check for tekton hook
Browse files Browse the repository at this point in the history
  • Loading branch information
ElderMatt committed Oct 12, 2023
1 parent afbe079 commit 0746e85
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/tasks/gitea/gitea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ export async function upsertTeam(
)
}

async function hasTekTonHook(repoApi: RepositoryApi): Promise<boolean> {
const hooks: any[] = await doApiCall(
errors,
`Getting hooks in repo "otomi/values"`,
() => repoApi.repoListGitHooks(orgName, 'values'),
400,
)

console.debug(`HOOKS: `, hooks)
let hasTektonHook = false
hooks.forEach((hook) => {
if (hook.name.includes('el-github-listener')) hasTektonHook = true
})
return hasTektonHook
}

export async function upsertRepo(
existingTeams: Team[] = [],
existingRepos: Repository[] = [],
Expand Down Expand Up @@ -100,9 +116,10 @@ export async function upsertRepo(
)
return undefined
}
export async function addHook(repoApi: RepositoryApi, hasTektonHook: boolean): Promise<void> {
export async function addHook(repoApi: RepositoryApi): Promise<void> {
console.debug('Check for Tekton hook')
if (!hasTektonHook) {
const hasHooks = await hasTekTonHook(repoApi)
if (!hasHooks) {
console.debug('No Tekton hook')
console.debug('Trying to add Tekton hook')
await doApiCall(
Expand Down Expand Up @@ -175,7 +192,7 @@ export default async function main(): Promise<void> {
422,
)

await addHook(repoApi, false)
await addHook(repoApi)

if (!hasArgo) return

Expand Down

0 comments on commit 0746e85

Please sign in to comment.