-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
feat: github orgs for /bake #41
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 18 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 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 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 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 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 clients | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/google/go-github/v54/github" | ||
) | ||
|
||
type GithubAPIClient struct { | ||
client *github.Client | ||
} | ||
|
||
func NewGithubTokenClient(token string) *GithubAPIClient { | ||
ctx := context.Background() | ||
s := &GithubAPIClient{ | ||
client: github.NewTokenClient(ctx, token), | ||
} | ||
return s | ||
} | ||
|
||
func NewGithubClient(httpClient *http.Client) *GithubAPIClient { | ||
s := &GithubAPIClient{ | ||
client: github.NewClient(httpClient), | ||
} | ||
return s | ||
} | ||
|
||
func (s *GithubAPIClient) 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 FilterGithubArchivedRepos(repos []*github.Repository) []*github.Repository { | ||
var filteredRepos []*github.Repository | ||
for _, repo := range repos { | ||
if !*repo.Archived { | ||
filteredRepos = append(filteredRepos, repo) | ||
} | ||
} | ||
return filteredRepos | ||
} | ||
|
||
func GetGithubRepoHTMLUrls(repos []*github.Repository) []string { | ||
var urls []string | ||
for _, repo := range repos { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: extra space here could be removed. |
||
htmlURL := repo.GetHTMLURL() | ||
if htmlURL != "" { | ||
urls = append(urls, htmlURL) | ||
} | ||
} | ||
return urls | ||
} |
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,50 @@ | ||
package clients | ||
|
||
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 TestFilterGithubArchivedRepos(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for adding tests! <3 |
||
totalCount := 10 | ||
archiveCount := 2 | ||
filteredCountExpected := (totalCount - archiveCount) | ||
originalRepoList := createRepoList("open-sauced", totalCount, archiveCount) | ||
filteredRepoList := FilterGithubArchivedRepos(originalRepoList) | ||
if len(filteredRepoList) != filteredCountExpected { | ||
t.Errorf("FilteredArchivedRepos() should yield %d items; got %d", filteredCountExpected, len(filteredRepoList)) | ||
} | ||
} | ||
|
||
func TestGetGithubRepoHTMLUrls(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 := GetGithubRepoHTMLUrls(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]) | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Looks like this is dead code and isn't used. Makes sense as part of a github client package if we needed a client generated from a token in the future. Curious to hear why it was included?