From e13eb7f4be3a7047efbe2ac841d8fa61465dd75c Mon Sep 17 00:00:00 2001 From: YCK1130 Date: Mon, 8 Jul 2024 15:06:04 +0100 Subject: [PATCH] chore: remove confusing output in list pr --- application/github/v0/client.go | 2 -- application/github/v0/commits.go | 20 ++++++++++++-------- application/github/v0/component_test.go | 22 +++------------------- application/github/v0/config/tasks.json | 5 +++-- application/github/v0/pull_request.go | 8 ++++---- 5 files changed, 22 insertions(+), 35 deletions(-) diff --git a/application/github/v0/client.go b/application/github/v0/client.go index 83901364b..abfac6c61 100644 --- a/application/github/v0/client.go +++ b/application/github/v0/client.go @@ -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 { diff --git a/application/github/v0/commits.go b/application/github/v0/commits.go index 4b43d38ae..32186115c 100644 --- a/application/github/v0/commits.go +++ b/application/github/v0/commits.go @@ -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"` @@ -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 @@ -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(), @@ -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 diff --git a/application/github/v0/component_test.go b/application/github/v0/component_test.go index d5bc6b671..877d36158 100644 --- a/application/github/v0/component_test.go +++ b/application/github/v0/component_test.go @@ -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", @@ -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, @@ -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, @@ -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, diff --git a/application/github/v0/config/tasks.json b/application/github/v0/config/tasks.json index 9b6fcaaba..e7b6cc3e3 100644 --- a/application/github/v0/config/tasks.json +++ b/application/github/v0/config/tasks.json @@ -563,7 +563,7 @@ "properties": { "id": { "description": "ID of the user", - "instillUIOrder": 1, + "instillUIOrder": 14, "title": "User id", "instillFormat": "integer", "instillAcceptFormats": [ @@ -577,7 +577,7 @@ }, "url": { "description": "URL of the user", - "instillUIOrder": 2, + "instillUIOrder": 15, "title": "User URL", "instillFormat": "string", "instillAcceptFormats": [ @@ -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, diff --git a/application/github/v0/pull_request.go b/application/github/v0/pull_request.go index 114ed3b3b..95d24da0e 100644 --- a/application/github/v0/pull_request.go +++ b/application/github/v0/pull_request.go @@ -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(), @@ -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 @@ -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 } @@ -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 }