Skip to content

Commit

Permalink
chore: remove confusing output in list pr
Browse files Browse the repository at this point in the history
  • Loading branch information
YCK1130 committed Jul 8, 2024
1 parent 0b36264 commit e13eb7f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 35 deletions.
2 changes: 0 additions & 2 deletions application/github/v0/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ type Client struct {
Repositories RepositoriesService
PullRequests PullRequestService
Issues IssuesService
owner string
repository string
}

func newClient(ctx context.Context, setup *structpb.Struct) Client {
Expand Down
20 changes: 12 additions & 8 deletions application/github/v0/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type RepositoriesService interface {
type Commit struct {
SHA string `json:"sha"`
Message string `json:"message"`
Stats CommitStats `json:"stats"`
Files []CommitFile `json:"files"`
Stats *CommitStats `json:"stats,omitempty"`
Files []CommitFile `json:"files,omitempty"`
}
type CommitStats struct {
Additions int `json:"additions"`
Expand All @@ -41,12 +41,17 @@ func (githubClient *Client) extractCommitFile(file *github.CommitFile) CommitFil
},
}
}
func (githubClient *Client) extractCommitInformation(ctx context.Context, originalCommit *github.RepositoryCommit) Commit {
func (githubClient *Client) extractCommitInformation(ctx context.Context, owner, repository string, originalCommit *github.RepositoryCommit, needCommitDetails bool) Commit {
if !needCommitDetails {
return Commit{
SHA: originalCommit.GetSHA(),
Message: originalCommit.GetCommit().GetMessage(),
}
}
stats := originalCommit.GetStats()
commitFiles := originalCommit.Files

if stats == nil || commitFiles == nil {
commit, err := githubClient.getCommit(ctx, githubClient.owner, githubClient.repository, originalCommit.GetSHA())
commit, err := githubClient.getCommit(ctx, owner, repository, originalCommit.GetSHA())
if err == nil {
// only update stats and files if there is no error
// otherwise, we will maintain the original commit information
Expand All @@ -58,11 +63,10 @@ func (githubClient *Client) extractCommitInformation(ctx context.Context, origin
for idx, file := range commitFiles {
files[idx] = githubClient.extractCommitFile(file)
}

return Commit{
SHA: originalCommit.GetSHA(),
Message: originalCommit.GetCommit().GetMessage(),
Stats: CommitStats{
Stats: &CommitStats{
Additions: stats.GetAdditions(),
Deletions: stats.GetDeletions(),
Changes: stats.GetTotal(),
Expand Down Expand Up @@ -101,7 +105,7 @@ func (githubClient *Client) getCommitTask(ctx context.Context, props *structpb.S
return nil, err
}
var resp GetCommitResp
resp.Commit = githubClient.extractCommitInformation(ctx, commit)
resp.Commit = githubClient.extractCommitInformation(ctx, owner, repository, commit, true)
out, err := base.ConvertToStructpb(resp)
if err != nil {
return nil, err
Expand Down
22 changes: 3 additions & 19 deletions application/github/v0/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,6 @@ func TestComponent_ListPullRequestsTask(t *testing.T) {
{
Message: "This is a fake commit",
SHA: "commitSHA",
Stats: CommitStats{
Additions: 1,
Deletions: 1,
Changes: 2,
},
Files: []CommitFile{
{
Filename: "filename",
Patch: "patch",
CommitStats: CommitStats{
Additions: 1,
Deletions: 1,
Changes: 2,
},
},
},
},
},
DiffURL: "https://fake-github.com/test_owner/test_repo/pull/1.diff",
Expand Down Expand Up @@ -154,7 +138,7 @@ func TestComponent_GetPullRequestTask(t *testing.T) {
{
Message: "This is a fake commit",
SHA: "commitSHA",
Stats: CommitStats{
Stats: &CommitStats{
Additions: 1,
Deletions: 1,
Changes: 2,
Expand Down Expand Up @@ -202,7 +186,7 @@ func TestComponent_GetPullRequestTask(t *testing.T) {
{
Message: "This is a fake commit",
SHA: "commitSHA",
Stats: CommitStats{
Stats: &CommitStats{
Additions: 1,
Deletions: 1,
Changes: 2,
Expand Down Expand Up @@ -502,7 +486,7 @@ func TestComponent_GetCommitTask(t *testing.T) {
Commit: Commit{
Message: "This is a fake commit",
SHA: "commitSHA",
Stats: CommitStats{
Stats: &CommitStats{
Additions: 1,
Deletions: 1,
Changes: 2,
Expand Down
5 changes: 3 additions & 2 deletions application/github/v0/config/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@
"properties": {
"id": {
"description": "ID of the user",
"instillUIOrder": 1,
"instillUIOrder": 14,
"title": "User id",
"instillFormat": "integer",
"instillAcceptFormats": [
Expand All @@ -577,7 +577,7 @@
},
"url": {
"description": "URL of the user",
"instillUIOrder": 2,
"instillUIOrder": 15,
"title": "User URL",
"instillFormat": "string",
"instillAcceptFormats": [
Expand Down Expand Up @@ -724,6 +724,7 @@
},
"TASK_LIST_PULL_REQUESTS": {
"instillShortDescription": "Get the list of all pull requests in a repository",
"description": "Get the list of all pull requests in a repository. Detailed information about each commit in a PR is omitted, please use the `Get Commit` task or the `Get Pull Request` task to get the details of a commit.",
"input": {
"description": "Please input the repository name and owner",
"instillUIOrder": 0,
Expand Down
8 changes: 4 additions & 4 deletions application/github/v0/pull_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type PullRequest struct {
ReviewCommentsNum int `json:"review_comments_num"`
}

func (githubClient *Client) extractPullRequestInformation(ctx context.Context, owner string, repository string, originalPr *github.PullRequest) (PullRequest, error) {
func (githubClient *Client) extractPullRequestInformation(ctx context.Context, owner string, repository string, originalPr *github.PullRequest, needCommitDetails bool) (PullRequest, error) {
resp := PullRequest{
ID: originalPr.GetID(),
Number: originalPr.GetNumber(),
Expand All @@ -56,7 +56,7 @@ func (githubClient *Client) extractPullRequestInformation(ctx context.Context, o
}
resp.Commits = make([]Commit, len(commits))
for idx, commit := range commits {
resp.Commits[idx] = githubClient.extractCommitInformation(ctx, commit)
resp.Commits[idx] = githubClient.extractCommitInformation(ctx, owner, repository, commit, needCommitDetails)
}
}
return resp, nil
Expand Down Expand Up @@ -95,7 +95,7 @@ func (githubClient *Client) listPullRequestsTask(ctx context.Context, props *str
}
PullRequests := make([]PullRequest, len(prs))
for idx, pr := range prs {
PullRequests[idx], err = githubClient.extractPullRequestInformation(ctx, owner, repository, pr)
PullRequests[idx], err = githubClient.extractPullRequestInformation(ctx, owner, repository, pr, false)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -170,7 +170,7 @@ func (githubClient *Client) getPullRequestTask(ctx context.Context, props *struc
}

var prResp GetPullRequestResp
prResp.PullRequest, err = githubClient.extractPullRequestInformation(ctx, owner, repository, pullRequest)
prResp.PullRequest, err = githubClient.extractPullRequestInformation(ctx, owner, repository, pullRequest, true)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit e13eb7f

Please sign in to comment.