-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(branches):
BranchesHandler
-> BranchProtectionsHandler
Signed-off-by: Lexus Drumgold <[email protected]>
- Loading branch information
1 parent
0abacec
commit f26fa7a
Showing
16 changed files
with
195 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/subdomains/branches/queries/__tests__/branch-protections.handler.spec-d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* @file Type Tests - BranchProtectionsHandler | ||
* @module branches/queries/tests/unit-d/BranchProtectionsHandler | ||
*/ | ||
|
||
import type { BranchProtection } from '#src/branches/types' | ||
import type { IQueryHandler } from '@nestjs/cqrs' | ||
import type TestSubject from '../branch-protections.handler' | ||
import type BranchProtectionsQuery from '../branch-protections.query' | ||
|
||
describe('unit-d:branches/queries/BranchProtectionsHandler', () => { | ||
it('should implement IQueryHandler<BranchProtectionsQuery, Branch[]>', () => { | ||
expectTypeOf<TestSubject>() | ||
.toMatchTypeOf< | ||
IQueryHandler<BranchProtectionsQuery, BranchProtection[]> | ||
>() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
...tests__/branches.query.functional.spec.ts → ...anch-protections.query.functional.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/subdomains/branches/queries/__tests__/branch-protections.query.spec-d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* @file Type Tests - BranchProtectionsQuery | ||
* @module branches/queries/tests/unit-d/BranchProtectionsQuery | ||
*/ | ||
|
||
import type { RepositoryQuery } from '#src/queries' | ||
import type TestSubject from '../branch-protections.query' | ||
|
||
describe('unit-d:branches/queries/BranchProtectionsQuery', () => { | ||
it('should extend RepositoryQuery', () => { | ||
expectTypeOf<TestSubject>().toMatchTypeOf<RepositoryQuery>() | ||
}) | ||
}) |
16 changes: 0 additions & 16 deletions
16
src/subdomains/branches/queries/__tests__/branches.handler.spec-d.ts
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
src/subdomains/branches/queries/__tests__/branches.query.spec-d.ts
This file was deleted.
Oops, something went wrong.
94 changes: 94 additions & 0 deletions
94
src/subdomains/branches/queries/branch-protections.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/** | ||
* @file Queries - BranchProtectionsHandler | ||
* @module repostructure/branches/queries/BranchProtectionsHandler | ||
*/ | ||
|
||
import type { BranchProtection } from '#src/branches/types' | ||
import { QueryHandler, type IQueryHandler } from '@nestjs/cqrs' | ||
import { Octokit } from '@octokit/core' | ||
import * as graphql from 'graphql' | ||
import gql from 'graphql-tag' | ||
import BranchProtectionsQuery from './branch-protections.query' | ||
|
||
/** | ||
* Branch protection rules query handler. | ||
* | ||
* @see {@linkcode BranchProtection} | ||
* @see {@linkcode BranchProtectionsQuery} | ||
* | ||
* @class | ||
* @implements {IQueryHandler<BranchProtectionsQuery, BranchProtection[]>} | ||
*/ | ||
@QueryHandler(BranchProtectionsQuery) | ||
class BranchProtectionsHandler | ||
implements IQueryHandler<BranchProtectionsQuery, BranchProtection[]> { | ||
/** | ||
* GraphQL query. | ||
* | ||
* @see https://docs.github.com/graphql/reference/objects#repository | ||
* | ||
* @protected | ||
* @readonly | ||
* @instance | ||
* @member {string} operation | ||
*/ | ||
protected readonly operation: string | ||
|
||
/** | ||
* Create a new branch protection rules query handler. | ||
* | ||
* @see {@linkcode Octokit} | ||
* | ||
* @param {Octokit} octokit - Hydrated octokit client | ||
*/ | ||
constructor(protected readonly octokit: Octokit) { | ||
this.operation = graphql.print(gql` | ||
query BranchProtections( | ||
$cursor: String, | ||
$owner: String!, | ||
$repo: String! | ||
) { | ||
payload: repository(name: $repo, owner: $owner) { | ||
id | ||
protections: branchProtectionRules(after: $cursor, first: 100) { | ||
nodes { | ||
id | ||
pattern | ||
} | ||
pageInfo { | ||
endCursor | ||
hasNextPage | ||
} | ||
} | ||
} | ||
} | ||
`) | ||
} | ||
|
||
/** | ||
* Execute a branch protection rules query. | ||
* | ||
* @see {@linkcode BranchProtection} | ||
* @see {@linkcode BranchProtectionsQuery} | ||
* | ||
* @public | ||
* @async | ||
* | ||
* @param {BranchProtectionsQuery} query - Query to execute | ||
* @return {Promise<BranchProtection[]>} Branch protection rules array | ||
*/ | ||
public async execute( | ||
query: BranchProtectionsQuery | ||
): Promise<BranchProtection[]> { | ||
const { | ||
payload | ||
} = await this.octokit.graphql.paginate<'protections', BranchProtection>( | ||
this.operation, | ||
query | ||
) | ||
|
||
return payload.protections.nodes | ||
} | ||
} | ||
|
||
export default BranchProtectionsHandler |
16 changes: 16 additions & 0 deletions
16
src/subdomains/branches/queries/branch-protections.query.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* @file Queries - BranchProtectionsQuery | ||
* @module repostructure/branches/queries/BranchProtectionsQuery | ||
*/ | ||
|
||
import { RepositoryQuery } from '#src/queries' | ||
|
||
/** | ||
* Branch protection rules query. | ||
* | ||
* @class | ||
* @extends {RepositoryQuery} | ||
*/ | ||
class BranchProtectionsQuery extends RepositoryQuery {} | ||
|
||
export default BranchProtectionsQuery |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.