| 1 | import { Injectable } from '@nestjs/common'; |
| 2 | |
| 3 | import { UnprocessableError } |
| 4 | import { TagNotFoundError } |
| 5 | import { BranchNotFoundError } |
| 6 | import { RepositoryBranchesService } |
| 7 | import { ReleasesService } |
| 8 | import type { GithubRepositoryTarget |
| 9 | import { GithubIssuesService } |
| 10 | |
| 11 | /** GitHub's git references, over the branch and release services that own them. */ |
| 12 | @Injectable() |
| 13 | export class GithubGitService |
| 14 | constructor( |
| 15 | private readonly github |
| 16 | private readonly branches |
| 17 | private readonly releases |
| 18 | ) {} |
| 19 | |
| 20 | /** `heads/<branch>` or `tags/<tag>`, with Ghost's rules for deleting a branch; anything else, or a ref that is not there, does not exist as GitHub words it. */ |
| 21 | async deleteRef( |
| 22 | { owner, repo |
| 23 | ref: string, |
| 24 | ) { |
| 25 | const { repository, |
| 26 | owner, |
| 27 | repo, |
| 28 | viewer, |
| 29 | 'DELETE /repos/:owner/:repo/git/refs/:ref', |
| 30 | ); |
| 31 | const target = |
| 32 | ...this.github. |
| 33 | requesterId: signedIn.userId |
| 34 | }; |
| 35 | const [namespace, |
| 36 | const name = |
| 37 | try { |
| 38 | if (namespace === |
| 39 | return await this |
| 40 | if (namespace === |
| 41 | return await this |
| 42 | } catch (error) |
| 43 | if ( |
| 44 | !(error instanceof BranchNotFoundError |
| 45 | !(error instanceof TagNotFoundError |
| 46 | ) |
| 47 | throw error; |
| 48 | } |
| 49 | throw new UnprocessableError( |
| 50 | } |
| 51 | } |