-
-
Notifications
You must be signed in to change notification settings - Fork 12
feat: github orgs for /bake #41
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
Open
mtfoley
wants to merge
19
commits into
open-sauced:beta
Choose a base branch
from
mtfoley:pull-org
base: beta
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
86c99f9
feat: github orgs for /bake
mtfoley a8c2b2a
use go-github client
mtfoley 3efcb6e
rename to htmlUrls
mtfoley 4a5618f
added unit tests
mtfoley bfccd90
update README
mtfoley d7ef35a
feat: github orgs for /bake
mtfoley 69f639f
use go-github client
mtfoley 51ce8d1
rename to htmlUrls
mtfoley 4b83e21
added unit tests
mtfoley f00484e
update README
mtfoley f45ff53
rebase and go mod tidy
mtfoley 5cf6630
restore uuid module import
mtfoley 532f6e1
wip: refactor to separate endpoint
mtfoley 479a7b2
address linter comments
mtfoley 81707e4
error channels, wait groups, utility method for getting a valid URL eβ¦
mtfoley 90ea5dc
rename test functions
mtfoley 721bd12
use goroutines when !Wait
mtfoley 6c7a286
address golangci-lint issues
mtfoley 0aacd84
chore: merge branch 'open-sauced:beta' into pull-org
mtfoley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,70 @@ | ||
package github | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/google/go-github/v54/github" | ||
) | ||
|
||
type GithubClient struct { | ||
client *github.Client | ||
} | ||
|
||
func NewTokenClient(token string) *GithubClient { | ||
ctx := context.Background() | ||
s := &GithubClient{ | ||
client: github.NewTokenClient(ctx, token), | ||
} | ||
return s | ||
} | ||
|
||
func NewClient(httpClient *http.Client) *GithubClient { | ||
s := &GithubClient{ | ||
client: github.NewClient(httpClient), | ||
} | ||
return s | ||
} | ||
|
||
func (s *GithubClient) ListReposByOrg(org string) ([]*github.Repository, error) { | ||
ctx := context.Background() | ||
opt := &github.RepositoryListByOrgOptions{ | ||
ListOptions: github.ListOptions{PerPage: 100}, | ||
} | ||
// get all pages of results | ||
var allRepos []*github.Repository | ||
for { | ||
repos, resp, err := s.client.Repositories.ListByOrg(ctx, org, opt) | ||
if err != nil { | ||
return allRepos, err | ||
} | ||
allRepos = append(allRepos, repos...) | ||
if resp.NextPage == 0 { | ||
break | ||
} | ||
opt.Page = resp.NextPage | ||
} | ||
return allRepos, nil | ||
} | ||
|
||
func FilterArchivedRepos(repos []*github.Repository) []*github.Repository { | ||
var filteredRepos []*github.Repository | ||
for _, repo := range repos { | ||
if !*repo.Archived { | ||
filteredRepos = append(filteredRepos, repo) | ||
} | ||
} | ||
return filteredRepos | ||
} | ||
|
||
func GetRepoHTMLUrls(repos []*github.Repository) []string { | ||
var urls []string | ||
for _, repo := range repos { | ||
|
||
htmlUrl := repo.GetHTMLURL() | ||
if htmlUrl != "" { | ||
urls = append(urls, htmlUrl) | ||
} | ||
} | ||
return urls | ||
} |
This file contains hidden or 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,50 @@ | ||
package github | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/google/go-github/v54/github" | ||
) | ||
|
||
func createRepoList(org string, totalCount int, archiveCount int) []*github.Repository { | ||
var repoList []*github.Repository | ||
for i := 0; i < totalCount; i++ { | ||
var archiveVal = (i < archiveCount) | ||
var htmlUrl = fmt.Sprintf("https://github.com/%s/repo-%d", org, i) | ||
repoList = append(repoList, &github.Repository{ | ||
Archived: &archiveVal, | ||
HTMLURL: &htmlUrl, | ||
}) | ||
} | ||
return repoList | ||
} | ||
|
||
func TestFilterArchivedRepos(t *testing.T) { | ||
totalCount := 10 | ||
archiveCount := 2 | ||
filteredCountExpected := (totalCount - archiveCount) | ||
originalRepoList := createRepoList("open-sauced", totalCount, archiveCount) | ||
filteredRepoList := FilterArchivedRepos(originalRepoList) | ||
if len(filteredRepoList) != filteredCountExpected { | ||
t.Errorf("FilteredArchivedRepos() should yield %d items; got %d", filteredCountExpected, len(filteredRepoList)) | ||
} | ||
} | ||
|
||
func TestGetRepoHTMLUrls(t *testing.T) { | ||
expected := []string{ | ||
"https://github.com/open-sauced/repo-0", | ||
"https://github.com/open-sauced/repo-1", | ||
"https://github.com/open-sauced/repo-2", | ||
} | ||
repos := createRepoList("open-sauced", 3, 0) | ||
got := GetRepoHTMLUrls(repos) | ||
if len(expected) != len(got) { | ||
t.Errorf("GetRepoHTMLUrls() should yield count matching input") | ||
} | ||
for i := 0; i < len(got); i++ { | ||
if got[i] != expected[i] { | ||
t.Errorf(`Expected GetRepoHTMLUrls()[%d] to yield "%s"; got "%s"`, i, expected[i], got[i]) | ||
} | ||
} | ||
} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.