-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add audit:repositories command
Fetch and display information for repositories within the Artsy GitHub organization. Initially to be used to aid our switch from a default branch of `master` to `main`. Usage: ``` $ artsy audit:repositories $ artsy audit:repositories --csv $ artsy audit:repositories --csv --default-branch=main $ artsy audit:repositories --csv --default-branch=main --pushed=">2021-05-01" ```
- Loading branch information
Showing
5 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,63 @@ | ||
import { flags } from "@oclif/command" | ||
import { cli } from "cli-ux" | ||
import { | ||
ArtsyRepositories, | ||
ArtsyRepositoriesQuery, | ||
} from "../../__generated__/graphql" | ||
import Command from "../../base" | ||
import { githubClient } from "../../utils/github" | ||
|
||
export default class Repositories extends Command { | ||
static description = "Audit GitHub repositories." | ||
|
||
static flags = { | ||
...Command.flags, | ||
...cli.table.flags(), | ||
"default-branch": flags.string({ | ||
description: "List only repos with a specific default branch", | ||
}), | ||
pushed: flags.string({ | ||
default: ">2021-01-01", | ||
description: "Pushed to", | ||
}), | ||
} | ||
|
||
async run() { | ||
const { flags } = this.parse(Repositories) | ||
|
||
const { | ||
data: { search }, | ||
} = await githubClient().query<ArtsyRepositoriesQuery>({ | ||
query: ArtsyRepositories, | ||
variables: { query: `org:artsy pushed:${flags.pushed}` }, | ||
}) | ||
|
||
let repositories = [] | ||
if (flags["default-branch"]) { | ||
search.nodes?.forEach(repository => { | ||
if (repository && repository.__typename === "Repository") { | ||
if (repository.defaultBranchRef?.name === flags["default-branch"]) { | ||
repositories.push(repository) | ||
} | ||
} | ||
}) | ||
} else { | ||
repositories = search.nodes as any[] | ||
} | ||
|
||
cli.table( | ||
repositories, | ||
{ | ||
name: {}, | ||
defaultBranch: { | ||
header: "Default Branch", | ||
get: row => row.defaultBranchRef && row.defaultBranchRef.name, | ||
}, | ||
}, | ||
{ | ||
printLine: this.log, | ||
...flags, | ||
} | ||
) | ||
} | ||
} |
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,14 @@ | ||
query ArtsyRepositories($query: String!) { | ||
search(query: $query, type: REPOSITORY, first: 100) { | ||
__typename | ||
nodes { | ||
__typename | ||
... on Repository { | ||
name | ||
defaultBranchRef { | ||
name | ||
} | ||
} | ||
} | ||
} | ||
} |
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,22 @@ | ||
import { expect, test } from "@oclif/test" | ||
import { RepositoriesFixture } from "../../fixtures/repositories" | ||
|
||
describe("scheduled:rfcs", () => { | ||
beforeEach(() => { | ||
process.env.GITHUB_TOKEN = "test" | ||
}) | ||
|
||
afterEach(() => { | ||
delete process.env.GITHUB_TOKEN | ||
}) | ||
|
||
test | ||
.nock("https://api.github.com", api => | ||
api.post("/graphql").reply(200, RepositoriesFixture) | ||
) | ||
.stdout() | ||
.command(["audit:repositories", "--csv"]) | ||
.it("lists repositories in the artsy github org", ctx => { | ||
expect(ctx.stdout.trim()).to.eq("Name,Default Branch\neigen,master") | ||
}) | ||
}) |
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,17 @@ | ||
export const RepositoriesFixture = { | ||
data: { | ||
search: { | ||
__typename: "SearchResultItemConnection", | ||
nodes: [ | ||
{ | ||
__typename: "Repository", | ||
name: "eigen", | ||
defaultBranchRef: { | ||
__typename: "Ref", | ||
name: "master", | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
} |