-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [MI-2481]:Fixed issue #613 on github (#12) * [MI-2481]:Fixed issue #681 on github * [MI-2481]:Fixed review fixes * [MI-2481]:Fixed review fixes * [MI-2481]:Fixed review fixes * [MI-2547]:Fixed review fixes for Github issue 613 and PR 626 (#14) * [MI-2547]:Fixed review fixes for Github issue 613 and PR 626 * [MI-2547]:Fixed review fixes * [MI-2547]:Fixed review fixes * [MI-2582]:Fixed review comments for github issue #613 (#15) * [MM-613]:Fixed review comments * [MI-3072]:Converted the LHS APIs into GraphQL (#32) * [MI-3012]: Converted user PRs API into GraphQL * [MI-3012]: Fixed review comments * [MI-3012]:fixed log message * [MI-3035]: Converted the get assignment API into GraphQL * [MI-3035]:Fixed self review comments * [MI-3035]: Fixed review comments * [MI-3072]:Converted review requested API to graphQL * [MI-3072]:Combined all the graphQL queries * [MI-3072]:Fixed CI errors * [MI-3072]:Fixed review comments * [MI-3072]:Fixed CI errors * [MI-3072]:Fixed review comments * [MI-3072]:Fixed review comments * [MM-613]:Changed namings * [MM-613]:Fixed review comments * [MM-613]:Fixed review comments * [MM-613]:Fixed panic error * [MM-613]:Fixed review comments * [MM-613]:Fixed lint errors * [MM-613]:Fixed review comment * [MM-613]:Fixed review comments * [MM-613]:Fixed review comments
- Loading branch information
1 parent
4ef49d5
commit 3ea161c
Showing
18 changed files
with
507 additions
and
260 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
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,62 @@ | ||
package graphql | ||
|
||
import ( | ||
"context" | ||
"net/url" | ||
"path" | ||
|
||
pluginapi "github.com/mattermost/mattermost-plugin-api" | ||
"github.com/pkg/errors" | ||
"github.com/shurcooL/githubv4" | ||
"golang.org/x/oauth2" | ||
) | ||
|
||
// Client encapsulates the third party package that communicates with Github GraphQL API | ||
type Client struct { | ||
client *githubv4.Client | ||
org string | ||
username string | ||
logger pluginapi.LogService | ||
} | ||
|
||
// NewClient creates and returns Client. The third party package that queries GraphQL is initialized here. | ||
func NewClient(logger pluginapi.LogService, token oauth2.Token, username, orgName, enterpriseBaseURL string) *Client { | ||
ts := oauth2.StaticTokenSource(&token) | ||
httpClient := oauth2.NewClient(context.Background(), ts) | ||
var client Client | ||
|
||
if enterpriseBaseURL == "" { | ||
client = Client{ | ||
username: username, | ||
client: githubv4.NewClient(httpClient), | ||
logger: logger, | ||
org: orgName, | ||
} | ||
} else { | ||
baseURL, err := url.Parse(enterpriseBaseURL) | ||
if err != nil { | ||
logger.Debug("Not able to parse the URL", "Error", err.Error()) | ||
return nil | ||
} | ||
|
||
baseURL.Path = path.Join(baseURL.Path, "api", "graphql") | ||
|
||
client = Client{ | ||
client: githubv4.NewEnterpriseClient(baseURL.String(), httpClient), | ||
username: username, | ||
org: orgName, | ||
logger: logger, | ||
} | ||
} | ||
|
||
return &client | ||
} | ||
|
||
// executeQuery takes a query struct and sends it to Github GraphQL API via helper package. | ||
func (c *Client) executeQuery(ctx context.Context, qry interface{}, params map[string]interface{}) error { | ||
if err := c.client.Query(ctx, qry, params); err != nil { | ||
return errors.Wrap(err, "error in executing query") | ||
} | ||
|
||
return nil | ||
} |
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,91 @@ | ||
package graphql | ||
|
||
import ( | ||
"github.com/shurcooL/githubv4" | ||
) | ||
|
||
type ( | ||
repositoryQuery struct { | ||
Name githubv4.String | ||
NameWithOwner githubv4.String | ||
URL githubv4.URI | ||
} | ||
|
||
authorQuery struct { | ||
Login githubv4.String | ||
} | ||
|
||
prSearchNodes struct { | ||
PullRequest struct { | ||
Body githubv4.String | ||
Number githubv4.Int | ||
AuthorAssociation githubv4.String | ||
CreatedAt githubv4.DateTime | ||
UpdatedAt githubv4.DateTime | ||
Repository repositoryQuery | ||
State githubv4.String | ||
Title githubv4.String | ||
Author authorQuery | ||
URL githubv4.URI | ||
} `graphql:"... on PullRequest"` | ||
} | ||
) | ||
|
||
type ( | ||
assignmentSearchNodes struct { | ||
Issue struct { | ||
Body githubv4.String | ||
Number githubv4.Int | ||
AuthorAssociation githubv4.String | ||
CreatedAt githubv4.DateTime | ||
UpdatedAt githubv4.DateTime | ||
Repository repositoryQuery | ||
State githubv4.String | ||
Title githubv4.String | ||
Author authorQuery | ||
URL githubv4.URI | ||
} `graphql:"... on Issue"` | ||
|
||
PullRequest struct { | ||
Body githubv4.String | ||
Number githubv4.Int | ||
AuthorAssociation githubv4.String | ||
CreatedAt githubv4.DateTime | ||
UpdatedAt githubv4.DateTime | ||
Repository repositoryQuery | ||
State githubv4.String | ||
Title githubv4.String | ||
Author authorQuery | ||
URL githubv4.URI | ||
} `graphql:"... on PullRequest"` | ||
} | ||
) | ||
|
||
var mainQuery struct { | ||
ReviewRequests struct { | ||
IssueCount int | ||
Nodes []prSearchNodes | ||
PageInfo struct { | ||
EndCursor githubv4.String | ||
HasNextPage bool | ||
} | ||
} `graphql:"pullRequest: search(first:100, after:$reviewsCursor, query: $prReviewQueryArg, type: ISSUE)"` | ||
|
||
Assignments struct { | ||
IssueCount int | ||
Nodes []assignmentSearchNodes | ||
PageInfo struct { | ||
EndCursor githubv4.String | ||
HasNextPage bool | ||
} | ||
} `graphql:"assignee: search(first:100, after:$assignmentsCursor, query: $assigneeQueryArg, type: ISSUE)"` | ||
|
||
OpenPullRequests struct { | ||
IssueCount int | ||
Nodes []prSearchNodes | ||
PageInfo struct { | ||
EndCursor githubv4.String | ||
HasNextPage bool | ||
} | ||
} `graphql:"graphql: search(first:100, after:$openPrsCursor, query: $prOpenQueryArg, type: ISSUE)"` | ||
} |
Oops, something went wrong.