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
4 changes: 4 additions & 0 deletions packages/das/src/api/api.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { MinersController } from "./miners/miners.controller";
import { MinersService } from "./miners/miners.service";
import { PullsController } from "./pulls/pulls.controller";
import { PullsService } from "./pulls/pulls.service";
import { ReposController } from "./repos/repos.controller";
import { ReposService } from "./repos/repos.service";

@Module({
imports: [
Expand All @@ -36,13 +38,15 @@ import { PullsService } from "./pulls/pulls.service";
DashboardController,
MinersController,
PullsController,
ReposController,
AdminController,
HealthController,
],
providers: [
DashboardService,
MinersService,
PullsService,
ReposService,
RequireApiKeyGuard,
],
})
Expand Down
27 changes: 27 additions & 0 deletions packages/das/src/api/repos/repos.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Controller, Get, Param } from "@nestjs/common";
import { ApiOperation, ApiParam, ApiTags } from "@nestjs/swagger";
import { ReposService } from "./repos.service";

@ApiTags("Repos")
@Controller("api/v1/repos")
export class ReposController {
constructor(private readonly repos: ReposService) {}

@Get(":owner/:repo/maintainers")
@ApiOperation({
summary: "Maintainer-role contributors for a repo",
description:
"Returns users whose latest known GitHub association for the repo " +
"is OWNER, MEMBER, or COLLABORATOR, synthesized from PR/issue/" +
"review/comment activity (contributor_repo_roles view). An unknown " +
"repo returns an empty maintainers list, not a 404.",
})
@ApiParam({ name: "owner", description: "Repository owner (org or user)" })
@ApiParam({ name: "repo", description: "Repository name" })
async getMaintainers(
@Param("owner") owner: string,
@Param("repo") repo: string,
): Promise<unknown> {
return this.repos.getMaintainers(owner, repo);
}
}
41 changes: 41 additions & 0 deletions packages/das/src/api/repos/repos.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* eslint-disable @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-assignment */
import { Injectable } from "@nestjs/common";
import { DataSource } from "typeorm";

@Injectable()
export class ReposService {
constructor(private readonly dataSource: DataSource) {}

async getMaintainers(
owner: string,
repo: string,
): Promise<{
repo_full_name: string;
generated_at: string;
maintainers: unknown[];
}> {
const repoFullName = `${owner}/${repo}`;

// The association literals must stay in sync with gittensor
// constants.py MAINTAINER_ASSOCIATIONS.
const rows = await this.dataSource.query(
`
SELECT
cr.author_github_id AS github_id,
cr.author_login AS login,
cr.author_association AS association
FROM contributor_repo_roles cr
WHERE LOWER(cr.repo_full_name) = LOWER($1)
AND cr.author_association IN ('OWNER', 'MEMBER', 'COLLABORATOR')
ORDER BY cr.author_github_id
`,
[repoFullName],
);

return {
repo_full_name: repoFullName.toLowerCase(),
generated_at: new Date().toISOString(),
maintainers: rows,
};
}
}
Loading