Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Github team slug to view_repo_ownership #831

Merged
merged 5 commits into from
Mar 6, 2024
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
6 changes: 6 additions & 0 deletions docs/database-migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ Once you have a draft migration, apply it via:
npm -w cli start migrate -- --stage DEV
```

You can then generate a new version of the Prisma Client via:

```bash
npx -w common prisma generate
```

## Applying a migration to CODE or PROD
Prerequisite:
1. You have an approved Pull Request
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
drop view if exists view_repo_ownership;

create view view_repo_ownership as
select ght.id as "github_team_id"
, ght.name as "github_team_name"
, ght.slug as "github_team_slug"
, tr.name as "short_repo_name"
, tr.full_name as "full_repo_name"
, tr.role_name
, tr.archived
, gtt.team_name as "galaxies_team"
, gtt.team_contact_email
from github_team_repositories tr
join github_teams ght on tr.team_id = ght.id
left join galaxies_teams_table gtt on ght.slug = gtt.team_primary_github_team
where tr.role_name = 'admin';
7 changes: 4 additions & 3 deletions packages/common/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -631,14 +631,15 @@ model guardian_github_actions_usage {
view view_repo_ownership {
github_team_id BigInt
github_team_name String
repo_name String
full_name String
github_team_slug String
short_repo_name String
full_repo_name String
role_name String
archived Boolean
galaxies_team String?
team_contact_email String?

@@unique([github_team_id, full_name])
@@unique([github_team_name, full_repo_name])
}

view aws_accounts {
Expand Down
5 changes: 3 additions & 2 deletions packages/common/prisma/views/public/view_repo_ownership.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
SELECT
ght.id AS github_team_id,
ght.name AS github_team_name,
tr.full_name AS repo_name,
tr.full_name,
ght.slug AS github_team_slug,
tr.name AS short_repo_name,
tr.full_name AS full_repo_name,
tr.role_name,
tr.archived,
gtt.team_name AS galaxies_team,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import type { Team } from '../../types';
import { createBranchProtectionEvents } from './branch-protection';

const nullOwner: view_repo_ownership = {
full_name: '',
full_repo_name: '',
github_team_id: BigInt(0),
github_team_name: '',
repo_name: '',
github_team_slug: '',
short_repo_name: '',
role_name: '',
archived: false,
galaxies_team: null,
Expand Down Expand Up @@ -40,9 +41,10 @@ describe('Team slugs should be findable for every team associated with a repo',

const teamOneOwner: view_repo_ownership = {
...nullOwner,
full_name: repo,
full_repo_name: repo,
github_team_id: BigInt(1),
github_team_name: 'Team One',
github_team_slug: teamOne.slug,
};

const actual = createBranchProtectionEvents(
Expand Down
2 changes: 1 addition & 1 deletion packages/repocop/src/remediation/shared-utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function findContactableOwners(
allRepoOwners: view_repo_ownership[],
teams: Team[],
): string[] {
const owners = allRepoOwners.filter((owner) => owner.full_name === repo);
const owners = allRepoOwners.filter((owner) => owner.full_repo_name === repo);
const teamSlugs = owners
.map((owner) => findTeamSlugFromId(owner.github_team_id, teams))
.filter((slug): slug is string => !!slug);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ const date = new Date('2021-01-01');
const ownershipRecord: view_repo_ownership = {
github_team_name: teamName,
github_team_id: teamId,
repo_name: removeRepoOwner(fullName),
full_name: fullName,
github_team_slug: teamSlug,
short_repo_name: removeRepoOwner(fullName),
full_repo_name: fullName,
role_name: '',
archived: false,
galaxies_team: null,
Expand All @@ -52,7 +53,7 @@ const anotherOwnershipRecord: view_repo_ownership = {
...ownershipRecord,
github_team_name: anotherTeam.name,
github_team_id: anotherTeam.id,
full_name: anotherFullName,
full_repo_name: anotherFullName,
};

const anotherRepocopRuleEvaluation: repocop_github_repository_rules = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function getOwningRepos(

const resultsOwnedByTeam = reposOwnedByTeam
.map((repo) => {
return results.find((result) => result.fullName === repo.full_name);
return results.find((result) => result.fullName === repo.full_repo_name);
})
.filter((result): result is EvaluationResult => result !== undefined);
akash1810 marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
Loading