Skip to content

Instantly share code, notes, and snippets.

@smoya

smoya/main.go Secret

Last active November 3, 2021 10:20
Show Gist options
  • Save smoya/4617304ec510c6f13e2bb9978b0ec824 to your computer and use it in GitHub Desktop.
Save smoya/4617304ec510c6f13e2bb9978b0ec824 to your computer and use it in GitHub Desktop.
List of repositories that contain workflow files not included in `.github` org repository at Wed 3 Nov 2021
package main
import (
"context"
"fmt"
"github.com/google/go-github/v39/github"
"golang.org/x/oauth2"
"net/http"
"os"
)
func main() {
token := os.Getenv("GH_TOKEN")
if token == "" {
panic("GH_TOKEN env var is required")
}
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
)
ctx := context.Background()
tc := oauth2.NewClient(ctx, ts)
client := github.NewClient(tc)
repositories, err := getRepositories(ctx, client)
if err != nil {
panic(err)
}
if len(repositories) == 0 {
panic("Repositories not found")
}
mainWorkflowsSlice, err := getWorkflows(ctx,client, ".github")
if err != nil {
panic(err)
}
mainWorkflows := make(map[string]*github.RepositoryContent, len(mainWorkflowsSlice))
for _, mw := range mainWorkflowsSlice {
mainWorkflows[mw.GetPath()] = mw
}
fmt.Println("Repository,File name,URL")
for _, repo := range repositories {
r := repo
if r.GetName() == ".github" {
continue
}
workflows, err := getWorkflows(ctx, client, r.GetName())
if err != nil {
panic(err)
}
if len(workflows) == 0 {
// no workflows found
continue
}
for _, w := range workflows {
if _, existsInMain := mainWorkflows[w.GetPath()]; existsInMain {
continue
}
fmt.Printf("%s,%s,%s\n", r.GetName(), w.GetName(), w.GetHTMLURL())
}
}
}
func getWorkflows(ctx context.Context, client *github.Client, repoName string) ([]*github.RepositoryContent, error) {
_, workflows, resp, err := client.Repositories.GetContents(ctx, "asyncapi", repoName, ".github/workflows", nil)
if resp.StatusCode == http.StatusNotFound {
// no content
return nil, nil
}
return workflows, err
}
func getRepositories (ctx context.Context, client *github.Client) ([]*github.Repository, error) {
var repos []*github.Repository
opt := &github.RepositoryListByOrgOptions{
ListOptions: github.ListOptions{PerPage: 50},
}
for {
r, resp, err := client.Repositories.ListByOrg(ctx, "asyncapi", opt)
if err != nil {
return nil, err
}
repos = append(repos, r...)
if resp.NextPage == 0 {
break
}
opt.Page = resp.NextPage
}
return repos, nil
}
Repository File name URL
spec lint.yml https://github.com/asyncapi/spec/blob/master/.github/workflows/lint.yml
spec new-spec-release.yml https://github.com/asyncapi/spec/blob/master/.github/workflows/new-spec-release.yml
spec release.yml https://github.com/asyncapi/spec/blob/master/.github/workflows/release.yml
spec update-spec.yaml https://github.com/asyncapi/spec/blob/master/.github/workflows/update-spec.yaml
website deploy.yml https://github.com/asyncapi/website/blob/master/.github/workflows/deploy.yml
generator pr-testing-with-test-project.yml https://github.com/asyncapi/generator/blob/master/.github/workflows/pr-testing-with-test-project.yml
generator release-docker.yml https://github.com/asyncapi/generator/blob/master/.github/workflows/release-docker.yml
generator templates-list-validation.yml https://github.com/asyncapi/generator/blob/master/.github/workflows/templates-list-validation.yml
generator update-docs-on-docs-commits.yml https://github.com/asyncapi/generator/blob/master/.github/workflows/update-docs-on-docs-commits.yml
asyncapi-react release-wc-and-playground.yml https://github.com/asyncapi/asyncapi-react/blob/master/.github/workflows/release-wc-and-playground.yml
parser-go .releaserc https://github.com/asyncapi/parser-go/blob/master/.github/workflows/.releaserc
parser-go release.yml https://github.com/asyncapi/parser-go/blob/master/.github/workflows/release.yml
parser-js update-docs-on-docs-commits.yml https://github.com/asyncapi/parser-js/blob/master/.github/workflows/update-docs-on-docs-commits.yml
converter-go .releaserc https://github.com/asyncapi/converter-go/blob/master/.github/workflows/.releaserc
converter-go release.yml https://github.com/asyncapi/converter-go/blob/master/.github/workflows/release.yml
tck publish-gh-pages.yml https://github.com/asyncapi/tck/blob/master/.github/workflows/publish-gh-pages.yml
html-template pr-testing-with-generator.yml https://github.com/asyncapi/html-template/blob/master/.github/workflows/pr-testing-with-generator.yml
ts-nats-template pull-request-integration-testing.yml https://github.com/asyncapi/ts-nats-template/blob/master/.github/workflows/pull-request-integration-testing.yml
dotnet-nats-template examples-pr-testing.yml https://github.com/asyncapi/dotnet-nats-template/blob/master/.github/workflows/examples-pr-testing.yml
shape-up-process deploy.yml https://github.com/asyncapi/shape-up-process/blob/master/.github/workflows/deploy.yml
shape-up-process scope-welcome.yml https://github.com/asyncapi/shape-up-process/blob/master/.github/workflows/scope-welcome.yml
template-for-generator-templates update-docs-on-docs-commits.yml https://github.com/asyncapi/template-for-generator-templates/blob/master/.github/workflows/update-docs-on-docs-commits.yml
generator-react-sdk update-docs-on-docs-commits.yml https://github.com/asyncapi/generator-react-sdk/blob/master/.github/workflows/update-docs-on-docs-commits.yml
modelina blackbox-testing.yml https://github.com/asyncapi/modelina/blob/master/.github/workflows/blackbox-testing.yml
modelina coverall.yml https://github.com/asyncapi/modelina/blob/master/.github/workflows/coverall.yml
event-gateway .releaserc https://github.com/asyncapi/event-gateway/blob/master/.github/workflows/.releaserc
event-gateway release.yml https://github.com/asyncapi/event-gateway/blob/master/.github/workflows/release.yml
community create-event-issue.yml https://github.com/asyncapi/community/blob/master/.github/workflows/create-event-issue.yml
community event_issue_templates https://github.com/asyncapi/community/tree/master/.github/workflows/event_issue_templates
community tsc_members_validator https://github.com/asyncapi/community/tree/master/.github/workflows/tsc_members_validator
community twitter-a-main-workflow.yml https://github.com/asyncapi/community/blob/master/.github/workflows/twitter-a-main-workflow.yml
community twitter-recurring-ideas.yml https://github.com/asyncapi/community/blob/master/.github/workflows/twitter-recurring-ideas.yml
community twitter-recurring-slack.yml https://github.com/asyncapi/community/blob/master/.github/workflows/twitter-recurring-slack.yml
community update-website.yml https://github.com/asyncapi/community/blob/master/.github/workflows/update-website.yml
community validate-tsc-members.yml https://github.com/asyncapi/community/blob/master/.github/workflows/validate-tsc-members.yml
cupid coverall.yml https://github.com/asyncapi/cupid/blob/master/.github/workflows/coverall.yml
temp-repo-test-for-website good-first-issue-closed.yaml https://github.com/asyncapi/temp-repo-test-for-website/blob/master/.github/workflows/good-first-issue-closed.yaml
temp-repo-test-for-website good-first-issue-created.yaml https://github.com/asyncapi/temp-repo-test-for-website/blob/master/.github/workflows/good-first-issue-created.yaml
temp-repo-test-for-website issue-pull-request-closed.yml https://github.com/asyncapi/temp-repo-test-for-website/blob/master/.github/workflows/issue-pull-request-closed.yml
temp-repo-test-for-website issue-pull-request-created.yml https://github.com/asyncapi/temp-repo-test-for-website/blob/master/.github/workflows/issue-pull-request-created.yml
temp-repo-test-for-website issue-pull-request-upvote.yaml https://github.com/asyncapi/temp-repo-test-for-website/blob/master/.github/workflows/issue-pull-request-upvote.yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment