-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
113 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
//go:generate mockgen -source pkg/handlers/gh/gh.go -destination internal/mock_gh/mock_gh.go GitHubService | ||
package main |
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,41 @@ | ||
// Package ghv3 provides GitHub V3 API implementation. | ||
package ghv3 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/codingpot/pr12er/server/pkg/handlers/gh" | ||
"github.com/google/go-github/v36/github" | ||
"golang.org/x/oauth2" | ||
) | ||
|
||
// GitHubV3 is the v3 implementation of gh.GitHubService. | ||
type GitHubV3 struct { | ||
client *github.Client | ||
} | ||
|
||
// CreateIssue create an issue. | ||
func (g GitHubV3) CreateIssue(title, body string, labels []string) (*gh.GitHubIssue, error) { | ||
create, _, err := g.client.Issues.Create(context.Background(), "codingpot", "pr12er", &github.IssueRequest{ | ||
Title: &title, | ||
Body: &body, | ||
Labels: &labels, | ||
}) | ||
|
||
if create == nil { | ||
return nil, err | ||
} | ||
return &gh.GitHubIssue{URL: create.GetURL()}, err | ||
} | ||
|
||
// Ensure the GitHubV3 implements gh.GitHubService interface. | ||
var _ gh.GitHubService = (*GitHubV3)(nil) | ||
|
||
func New(apiKey string) *GitHubV3 { | ||
client := github.NewClient(oauth2.NewClient(context.Background(), oauth2.StaticTokenSource( | ||
&oauth2.Token{AccessToken: apiKey}, | ||
))) | ||
return &GitHubV3{ | ||
client: client, | ||
} | ||
} |
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,9 @@ | ||
package gh | ||
|
||
type GitHubIssue struct { | ||
URL string | ||
} | ||
|
||
type GitHubService interface { | ||
CreateIssue(title, body string, labels []string) (*GitHubIssue, error) | ||
} |