Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support GitHub Enterprise #464

Merged
merged 1 commit into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/Masterminds/sprig/v3 v3.2.2
github.com/antonmedv/expr v1.9.0
github.com/drone/envsubst v1.0.3
github.com/google/go-github/v44 v44.1.0
github.com/google/uuid v1.1.2 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/mattn/go-colorable v0.1.12
Expand All @@ -19,7 +20,7 @@ require (
github.com/suzuki-shunsuke/go-httpclient v1.0.0
github.com/suzuki-shunsuke/go-timeout v1.0.0
github.com/urfave/cli/v2 v2.8.1
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
golang.org/x/oauth2 v0.0.0-20210113205817-d3ed898aa8a3
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1
gopkg.in/yaml.v2 v2.4.0
)
22 changes: 17 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,14 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.1 h1:JFrFEBb2xKufg6XkJsJr+WbKb4FQlURi5RUcBveYu9k=
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-github/v44 v44.1.0 h1:shWPaufgdhr+Ad4eo/pZv9ORTxFpsxPEPEuuXAKIQGA=
github.com/google/go-github/v44 v44.1.0/go.mod h1:iWn00mWcP6PRWHhXm0zuFJ8wbEjE5AGO5D5HXYM4zgw=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
Expand Down Expand Up @@ -211,8 +217,9 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -268,8 +275,9 @@ golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA=
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -312,9 +320,13 @@ golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 h1:foEbQz/B0Oz6YIqu/69kfXPYeFQAuuMYFkjaqXzl5Wo=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down Expand Up @@ -368,7 +380,6 @@ golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
Expand All @@ -391,8 +402,9 @@ google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/appengine v1.6.6 h1:lMO5rYAqUxkmaj76jAkRUvt5JZgFymx/+Q5Mzfivuhc=
google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
Expand Down
25 changes: 6 additions & 19 deletions pkg/cmd/exec.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package cmd

import (
"context"
"fmt"
"os"
"strconv"

"github.com/suzuki-shunsuke/github-comment/pkg/api"
"github.com/suzuki-shunsuke/github-comment/pkg/comment"
"github.com/suzuki-shunsuke/github-comment/pkg/config"
"github.com/suzuki-shunsuke/github-comment/pkg/execute"
"github.com/suzuki-shunsuke/github-comment/pkg/expr"
Expand Down Expand Up @@ -53,22 +51,6 @@ func existFile(p string) bool {
return err == nil
}

func getExecCommenter(ctx context.Context, opts *option.ExecOptions) api.Commenter {
if opts.DryRun {
return &comment.Mock{
Stderr: os.Stderr,
Silent: opts.Silent,
}
}
if opts.SkipNoToken && opts.Token == "" {
return &comment.Mock{
Stderr: os.Stderr,
Silent: opts.Silent,
}
}
return comment.New(ctx, opts.Token)
}

func (runner *Runner) execAction(c *cli.Context) error {
opts := &option.ExecOptions{}
if err := parseExecOptions(opts, c); err != nil {
Expand Down Expand Up @@ -99,13 +81,18 @@ func (runner *Runner) execAction(c *cli.Context) error {

var pt api.Platform = platform.Get(getPlatformParam(cfg.Complement))

commenter, err := getCommenter(c.Context, &opts.Options, cfg)
if err != nil {
return fmt.Errorf("initialize commenter: %w", err)
}

ctrl := api.ExecController{
Wd: wd,
Getenv: os.Getenv,
Stdin: runner.Stdin,
Stdout: runner.Stdout,
Stderr: runner.Stderr,
Commenter: getExecCommenter(c.Context, opts),
Commenter: commenter,
Renderer: &template.Renderer{
Getenv: os.Getenv,
},
Expand Down
30 changes: 8 additions & 22 deletions pkg/cmd/hide.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package cmd

import (
"context"
"fmt"
"os"
"strconv"

"github.com/suzuki-shunsuke/github-comment/pkg/api"
"github.com/suzuki-shunsuke/github-comment/pkg/comment"
"github.com/suzuki-shunsuke/github-comment/pkg/config"
"github.com/suzuki-shunsuke/github-comment/pkg/expr"
"github.com/suzuki-shunsuke/github-comment/pkg/option"
"github.com/suzuki-shunsuke/github-comment/pkg/platform"
"github.com/urfave/cli/v2"
"golang.org/x/crypto/ssh/terminal"
"golang.org/x/term"
)

// parseHideOptions parses the command line arguments of the subcommand "hide".
Expand All @@ -33,23 +31,6 @@ func parseHideOptions(opts *option.HideOptions, c *cli.Context) error {
return nil
}

func getHideCommenter(ctx context.Context, opts *option.HideOptions) api.Commenter {
if opts.DryRun {
return &comment.Mock{
Stderr: os.Stderr,
Silent: opts.Silent,
}
}
if opts.SkipNoToken && opts.Token == "" {
return &comment.Mock{
Stderr: os.Stderr,
Silent: opts.Silent,
}
}

return comment.New(ctx, opts.Token)
}

// hideAction is an entrypoint of the subcommand "hide".
func (runner *Runner) hideAction(c *cli.Context) error {
if a := os.Getenv("GITHUB_COMMENT_SKIP"); a != "" {
Expand Down Expand Up @@ -84,14 +65,19 @@ func (runner *Runner) hideAction(c *cli.Context) error {

var pt api.Platform = platform.Get(getPlatformParam(cfg.Complement))

commenter, err := getCommenter(c.Context, &opts.Options, cfg)
if err != nil {
return fmt.Errorf("initialize commenter: %w", err)
}

ctrl := api.HideController{
Wd: wd,
Getenv: os.Getenv,
HasStdin: func() bool {
return !terminal.IsTerminal(0)
return !term.IsTerminal(0)
},
Stderr: runner.Stderr,
Commenter: getHideCommenter(c.Context, opts),
Commenter: commenter,
Platform: pt,
Config: cfg,
Expr: &expr.Expr{},
Expand Down
19 changes: 12 additions & 7 deletions pkg/cmd/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/suzuki-shunsuke/github-comment/pkg/platform"
"github.com/suzuki-shunsuke/github-comment/pkg/template"
"github.com/urfave/cli/v2"
"golang.org/x/crypto/ssh/terminal"
"golang.org/x/term"
)

func parseVarsFlag(varsSlice []string) (map[string]string, error) {
Expand Down Expand Up @@ -80,21 +80,21 @@ func parsePostOptions(opts *option.PostOptions, c *cli.Context) error {
return nil
}

func getPostCommenter(ctx context.Context, opts *option.PostOptions) api.Commenter {
func getCommenter(ctx context.Context, opts *option.Options, cfg *config.Config) (api.Commenter, error) {
if opts.DryRun {
return &comment.Mock{
Stderr: os.Stderr,
Silent: opts.Silent,
}
}, nil
}
if opts.SkipNoToken && opts.Token == "" {
return &comment.Mock{
Stderr: os.Stderr,
Silent: opts.Silent,
}
}, nil
}

return comment.New(ctx, opts.Token)
return comment.New(ctx, opts.Token, cfg.GHEBaseURL, cfg.GHEGraphQLEndpoint) //nolint:wrapcheck
}

func setLogLevel(logLevel string) {
Expand Down Expand Up @@ -144,15 +144,20 @@ func (runner *Runner) postAction(c *cli.Context) error {

var pt api.Platform = platform.Get(getPlatformParam(cfg.Complement))

commenter, err := getCommenter(c.Context, &opts.Options, cfg)
if err != nil {
return fmt.Errorf("initialize commenter: %w", err)
}

ctrl := api.PostController{
Wd: wd,
Getenv: os.Getenv,
HasStdin: func() bool {
return !terminal.IsTerminal(0)
return !term.IsTerminal(0)
},
Stdin: runner.Stdin,
Stderr: runner.Stderr,
Commenter: getPostCommenter(c.Context, opts),
Commenter: commenter,
Renderer: &template.Renderer{
Getenv: os.Getenv,
},
Expand Down
79 changes: 36 additions & 43 deletions pkg/comment/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import (
"encoding/json"
"errors"
"fmt"
"net/http"
"strconv"
"strings"

"github.com/google/go-github/v44/github"
"github.com/shurcooL/githubv4"
"github.com/suzuki-shunsuke/go-httpclient/httpclient"
"golang.org/x/oauth2"
Expand All @@ -27,20 +26,31 @@ type Comment struct {
}

type Commenter struct {
HTTPClient httpclient.Client
Token string

client *github.Client
V4Client *githubv4.Client
}

func New(ctx context.Context, token string) *Commenter {
return &Commenter{
Token: token,
HTTPClient: httpclient.New("https://api.github.com"),
V4Client: githubv4.NewClient(oauth2.NewClient(ctx, oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
))),
func New(ctx context.Context, token, gheBaseURL, gheGraphQLEndpoint string) (*Commenter, error) {
httpClient := oauth2.NewClient(ctx, oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
))
commenter := &Commenter{}
if gheBaseURL == "" {
commenter.client = github.NewClient(httpClient)
} else {
client, err := github.NewEnterpriseClient(gheBaseURL, gheBaseURL, httpClient)
if err != nil {
return nil, fmt.Errorf("initialize GitHub Enterprise API Client: %w", err)
}
commenter.client = client
}
if gheGraphQLEndpoint == "" {
commenter.V4Client = githubv4.NewClient(httpClient)
} else {
commenter.V4Client = githubv4.NewEnterpriseClient(gheGraphQLEndpoint, httpClient)
}

return commenter, nil
}

type ValidationErrors struct {
Expand All @@ -51,30 +61,23 @@ type ValidationError struct {
Message string `json:"message"`
}

func (commenter *Commenter) getPath(cmt *Comment) string {
if cmt.PRNumber != 0 {
return "/repos/" + cmt.Org + "/" + cmt.Repo + "/issues/" + strconv.Itoa(cmt.PRNumber) + "/comments"
}
return "/repos/" + cmt.Org + "/" + cmt.Repo + "/commits/" + cmt.SHA1 + "/comments"
}

func (commenter *Commenter) create(ctx context.Context, cmt *Comment, tooLong bool) error {
body := cmt.Body
if tooLong {
body = cmt.BodyForTooLong
}
_, err := commenter.HTTPClient.Call(ctx, httpclient.CallParams{ //nolint:bodyclose
Method: http.MethodPost,
Path: commenter.getPath(cmt),
Header: http.Header{
"Authorization": []string{"token " + commenter.Token},
},
RequestBody: map[string]string{
"body": body,
},
})
if err != nil {
return fmt.Errorf("send a comment by GitHub API: %w", err)
if cmt.PRNumber != 0 {
if _, _, err := commenter.client.Issues.CreateComment(ctx, cmt.Org, cmt.Repo, cmt.PRNumber, &github.IssueComment{
Body: github.String(body),
}); err != nil {
return fmt.Errorf("send a comment to issue or pull request by GitHub API: %w", err)
}
} else {
if _, _, err := commenter.client.Repositories.CreateComment(ctx, cmt.Org, cmt.Repo, cmt.SHA1, &github.RepositoryComment{
Body: github.String(body),
}); err != nil {
return fmt.Errorf("send a comment to commit by GitHub API: %w", err)
}
}
return nil
}
Expand Down Expand Up @@ -205,19 +208,9 @@ func (commenter *Commenter) List(ctx context.Context, pr *PullRequest) ([]*Issue
}

func (commenter *Commenter) GetAuthenticatedUser(ctx context.Context) (string, error) {
user := struct {
Login string `json:"login"`
}{}
_, err := commenter.HTTPClient.Call(ctx, httpclient.CallParams{ //nolint:bodyclose
Method: http.MethodGet,
Path: "/user",
Header: http.Header{
"Authorization": []string{"token " + commenter.Token},
},
ResponseBody: &user,
})
user, _, err := commenter.client.Users.Get(ctx, "")
if err != nil {
return "", fmt.Errorf("get an authenticated user by GitHub API: %w", err)
}
return user.Login, nil
return user.GetLogin(), nil
}