Documentation
¶
Overview ¶
Package prdiff provides a function to get the diff of a pull request using GitHub API or git command. It first tries to get the diff via the GitHub API, and falls back to git command if it fails.
Example ¶
package main
import (
"context"
"fmt"
"log"
"github.com/suzuki-shunsuke/go-pr-diff/prdiff"
)
func main() {
c, err := prdiff.NewClient(nil, "")
if err != nil {
log.Fatal(err)
}
// Get diff of https://github.com/suzuki-shunsuke/mkghtag/pull/1080
diff, err := c.GetDiff(context.Background(), "suzuki-shunsuke", "mkghtag", 1080)
if err != nil {
log.Fatal(err)
}
fmt.Print(diff)
}
Output: diff --git a/.github/workflows/wc-test.yaml b/.github/workflows/wc-test.yaml index 1f703973..cc980f16 100644 --- a/.github/workflows/wc-test.yaml +++ b/.github/workflows/wc-test.yaml @@ -12,7 +12,7 @@ jobs: uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: persist-credentials: false - - uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0 + - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 with: go-version-file: go.mod cache: true
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a client to get the diff of a pull request.
func NewClient ¶
NewClient creates a new Client. baseURL is a base URL for GitHub Enterprise. If baseURL is empty, github.com is used. hc is used to call GitHub API using google/go-github.
func (*Client) GetDiff ¶
GetDiff returns the diff of a pull request. GetDiff first tries to get the diff via the GitHub API, and falls back to git command if it fails. If the current directory is a git repository, the pull request base head SHA and merge-base SHA are fetched via git command in the current repository, meaning the current repository may be polluted.