前置き
個人OSSに入れてるdependabotでmoduleをアップデートしてたらgolangci-lintでこういうwarningが出ていたので気づいた。 *1
Running [/home/runner/golangci-lint-1.60.3-linux-amd64/golangci-lint run] in [/home/runner/work/gitpanda/gitpanda] ...
Error: gitlab/blob_fetcher.go:19:54: SA1019: gitlab.Client is deprecated: use gitlab.com/gitlab-org/api/client-go instead. See https://gitlab.com/gitlab-org/api/client-go (staticcheck)
func (f *blobFetcher) fetchPath(path string, client *gitlab.Client, isDebugLogging bool) (*Page, error) {
^
Error: gitlab/commit_fetcher.go:15:56: SA1019: gitlab.Client is deprecated: use gitlab.com/gitlab-org/api/client-go instead. See https://gitlab.com/gitlab-org/api/client-go (staticcheck)
func (f *commitFetcher) fetchPath(path string, client *gitlab.Client, isDebugLogging bool) (*Page, error) {
^
Error: gitlab/fetcher.go:12:33: SA1019: gitlab.Client is deprecated: use gitlab.com/gitlab-org/api/client-go instead. See https://gitlab.com/gitlab-org/api/client-go (staticcheck)
fetchPath(path string, client *gitlab.Client, isDebugLogging bool) (*Page, error)
^
Error: gitlab/url_parser.go:41:17: SA1019: gitlab.NewClient is deprecated: This module has been migrated to gitlab.com/gitlab-org/api/client-go. See https://gitlab.com/gitlab-org/api/client-go (staticcheck)
client, err := gitlab.NewClient(params.PrivateToken, options...)
^
GoでGitLabのAPIを使う時には https://github.com/xanzy/go-gitlab を使うんだけど、https://gitlab.com/gitlab-org/api/client-go に移管したらしい。
golangci-lintを入れていなかったら絶対気づかなかったので入れててよかった〜
雑に置き換えるコマンド
基本的には移管前後でパッケージの構成は変わらないので文字列置換でいいんだけど複数のリポジトリで対応する必要があったのでコマンドで全部できるようにしました。
手元のリポジトリだとこれで全部書き換えました。
find . -name '*.go' -type f -exec sed -i '' 's|github.com/xanzy/go-gitlab|gitlab.com/gitlab-org/api/client-go|g' {} +
sed -i '' 's|github.com/xanzy/go-gitlab v[^ ]*|gitlab.com/gitlab-org/api/client-go latest|' go.mod
go mod tidy
gofmt -w .