Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pr-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
cache: npm
node-version-file: package.json
- run: bash "${GITHUB_WORKSPACE}/scripts/pr_test/pr_super_lint/npm_ci.sh"
- uses: super-linter/super-linter/slim@502f4fe48a81a392756e173e39a861f8c8efe056 # v8.3.0
- uses: super-linter/super-linter/slim@47984f49b4e87383eed97890fe2dca6063bbd9c3 # v8.3.1
env:
LINTER_RULES_PATH: .
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
repos:
- repo: https://github.com/zricethezav/gitleaks
rev: v8.29.1
rev: v8.30.0
hooks:
- id: gitleaks
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.25.4-bookworm@sha256:e17419604b6d1f9bc245694425f0ec9b1b53685c80850900a376fb10cb0f70cb AS builder
FROM golang:1.25.5-bookworm@sha256:09f53deea14d4019922334afe6258b7b776afc1d57952be2012f2c8c4076db05 AS builder

WORKDIR /app

Expand Down
6 changes: 3 additions & 3 deletions cmd/health_check/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/cockroachdb/errors"

libHttp "hato-bot-go/lib/http"
"hato-bot-go/lib/httpclient"
)

func main() {
Expand All @@ -23,9 +23,9 @@ func main() {
panic(errors.Wrap(err, "Failed to http.NewRequestWithContext"))
}

resp, err := libHttp.ExecuteHTTPRequest(http.DefaultClient, req)
resp, err := httpclient.ExecuteHTTPRequest(http.DefaultClient, req)
if err != nil {
panic(errors.Wrap(err, "Failed to libHttp.ExecuteHTTPRequest"))
panic(errors.Wrap(err, "Failed to httpclient.ExecuteHTTPRequest"))
}
defer func(Body io.ReadCloser) {
if closeErr := Body.Close(); closeErr != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module hato-bot-go

go 1.25.4
go 1.25.5

require (
github.com/cockroachdb/errors v1.12.0
Expand Down
14 changes: 7 additions & 7 deletions lib/amesh/amesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"golang.org/x/exp/constraints"

"hato-bot-go/lib"
libHttp "hato-bot-go/lib/http"
"hato-bot-go/lib/httpclient"
)

const Version = "1.0"
Expand Down Expand Up @@ -282,9 +282,9 @@ func ParseLocationWithClient(ctx context.Context, req *ParseLocationWithClientPa
if err != nil {
return nil, errors.Wrap(err, "Failed to http.NewRequestWithContext")
}
resp, err := libHttp.ExecuteHTTPRequest(req.Client, httpReq)
resp, err := httpclient.ExecuteHTTPRequest(req.Client, httpReq)
if err != nil {
return nil, errors.Wrap(err, "Failed to libHttp.ExecuteHTTPRequest")
return nil, errors.Wrap(err, "Failed to httpclient.ExecuteHTTPRequest")
}

body, err := handleHTTPResponse(resp)
Expand Down Expand Up @@ -513,7 +513,7 @@ func downloadTile(ctx context.Context, client *http.Client, tileURL string) (img
}
req.Header.Set("User-Agent", "hato-bot-go/"+Version)

resp, err := libHttp.ExecuteHTTPRequest(client, req)
resp, err := httpclient.ExecuteHTTPRequest(client, req)
if err != nil {
return nil, errors.Wrap(err, "Failed to ExecuteHTTPRequest")
}
Expand All @@ -536,13 +536,13 @@ func makeHTTPRequest(ctx context.Context, client *http.Client, url string) (*htt
if err != nil {
return nil, errors.Wrap(err, "Failed to http.NewRequestWithContext")
}
resp, err := libHttp.ExecuteHTTPRequest(client, req)
resp, err := httpclient.ExecuteHTTPRequest(client, req)
if err != nil {
if errors.Is(err, libHttp.ErrHTTPRequestError) {
if errors.Is(err, httpclient.ErrHTTPRequestError) {
return &httpRequestResult{Body: nil, IsEmpty: true}, nil
}

return nil, errors.Wrap(err, "Failed to libHttp.ExecuteHTTPRequest")
return nil, errors.Wrap(err, "Failed to httpclient.ExecuteHTTPRequest")
}

body, err := handleHTTPResponse(resp)
Expand Down
28 changes: 14 additions & 14 deletions lib/amesh/amesh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

"hato-bot-go/lib"
"hato-bot-go/lib/amesh"
libHttp "hato-bot-go/lib/http"
"hato-bot-go/lib/httpclient"
)

// httpMockConfig モックHTTPクライアントの設定
Expand Down Expand Up @@ -396,7 +396,7 @@ func TestParseLocationWithClient(t *testing.T) {
{
name: "成功したジオコーディング",
params: &amesh.ParseLocationWithClientParams{
Client: libHttp.NewMockHTTPClient(http.StatusOK, `{
Client: httpclient.NewMockHTTPClient(http.StatusOK, `{
"Feature": [
{
"Name": "東京都",
Expand All @@ -421,7 +421,7 @@ func TestParseLocationWithClient(t *testing.T) {
{
name: "座標文字列の解析",
params: &amesh.ParseLocationWithClientParams{
Client: libHttp.NewMockHTTPClient(http.StatusOK, `{
Client: httpclient.NewMockHTTPClient(http.StatusOK, `{
"Feature": [
{
"Name": "東京都",
Expand All @@ -446,7 +446,7 @@ func TestParseLocationWithClient(t *testing.T) {
{
name: "空の場所は東京がデフォルト",
params: &amesh.ParseLocationWithClientParams{
Client: libHttp.NewMockHTTPClient(http.StatusOK, `{
Client: httpclient.NewMockHTTPClient(http.StatusOK, `{
"Feature": [
{
"Name": "東京都",
Expand All @@ -471,7 +471,7 @@ func TestParseLocationWithClient(t *testing.T) {
{
name: "座標文字列(整数)",
params: &amesh.ParseLocationWithClientParams{
Client: libHttp.NewMockHTTPClient(http.StatusOK, `{
Client: httpclient.NewMockHTTPClient(http.StatusOK, `{
"Feature": [
{
"Name": "東京都",
Expand All @@ -495,7 +495,7 @@ func TestParseLocationWithClient(t *testing.T) {
{
name: "無効な座標文字列(1つの数値のみ)",
params: &amesh.ParseLocationWithClientParams{
Client: libHttp.NewMockHTTPClient(http.StatusOK, `{
Client: httpclient.NewMockHTTPClient(http.StatusOK, `{
"Feature": [
{
"Name": "東京都",
Expand All @@ -519,18 +519,18 @@ func TestParseLocationWithClient(t *testing.T) {
{
name: "無効な座標文字列",
params: &amesh.ParseLocationWithClientParams{
Client: libHttp.NewMockHTTPClient(http.StatusBadRequest, `{"Error": "Invalid place"}`),
Client: httpclient.NewMockHTTPClient(http.StatusBadRequest, `{"Error": "Invalid place"}`),
GeocodeRequest: amesh.GeocodeRequest{
Place: "invalid coordinates",
APIKey: "test_key",
},
},
expectError: libHttp.ErrHTTPRequestError,
expectError: httpclient.ErrHTTPRequestError,
},
{
name: "無効な座標フォーマット",
params: &amesh.ParseLocationWithClientParams{
Client: libHttp.NewMockHTTPClient(http.StatusOK, `{
Client: httpclient.NewMockHTTPClient(http.StatusOK, `{
"Feature": [
{
"Name": "東京都",
Expand All @@ -550,18 +550,18 @@ func TestParseLocationWithClient(t *testing.T) {
{
name: "APIがエラーステータスを返す",
params: &amesh.ParseLocationWithClientParams{
Client: libHttp.NewMockHTTPClient(http.StatusBadRequest, `{"Error": "Invalid API key"}`),
Client: httpclient.NewMockHTTPClient(http.StatusBadRequest, `{"Error": "Invalid API key"}`),
GeocodeRequest: amesh.GeocodeRequest{
Place: "東京",
APIKey: "invalid_key",
},
},
expectError: libHttp.ErrHTTPRequestError,
expectError: httpclient.ErrHTTPRequestError,
},
{
name: "結果が見つからない",
params: &amesh.ParseLocationWithClientParams{
Client: libHttp.NewMockHTTPClient(http.StatusOK, `{"Feature": []}`),
Client: httpclient.NewMockHTTPClient(http.StatusOK, `{"Feature": []}`),
GeocodeRequest: amesh.GeocodeRequest{
Place: "nonexistent place",
APIKey: "test_key",
Expand All @@ -572,7 +572,7 @@ func TestParseLocationWithClient(t *testing.T) {
{
name: "不正なJSON",
params: &amesh.ParseLocationWithClientParams{
Client: libHttp.NewMockHTTPClient(http.StatusOK, `{"Feature": [invalid json}`),
Client: httpclient.NewMockHTTPClient(http.StatusOK, `{"Feature": [invalid json}`),
GeocodeRequest: amesh.GeocodeRequest{
Place: "東京",
APIKey: "test_key",
Expand All @@ -583,7 +583,7 @@ func TestParseLocationWithClient(t *testing.T) {
{
name: "座標数が足りない場合",
params: &amesh.ParseLocationWithClientParams{
Client: libHttp.NewMockHTTPClient(http.StatusOK, `{
Client: httpclient.NewMockHTTPClient(http.StatusOK, `{
"Feature": [
{
"Name": "東京都",
Expand Down
2 changes: 1 addition & 1 deletion lib/http/http.go → lib/httpclient/http.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package http
package httpclient

import (
"net/http"
Expand Down
2 changes: 1 addition & 1 deletion lib/http/mock_client.go → lib/httpclient/mock_client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package http
package httpclient

import (
"io"
Expand Down
6 changes: 3 additions & 3 deletions lib/misskey/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

"hato-bot-go/lib"
"hato-bot-go/lib/amesh"
libHttp "hato-bot-go/lib/http"
"hato-bot-go/lib/httpclient"
)

// エラー定数
Expand Down Expand Up @@ -121,7 +121,7 @@ func (bot *Bot) UploadFile(ctx context.Context, reader io.Reader, fileName strin
req.Header.Set("Content-Type", writer.FormDataContentType())
req.Header.Set("User-Agent", bot.UserAgent)

resp, err := libHttp.ExecuteHTTPRequest(bot.BotSetting.Client, req)
resp, err := httpclient.ExecuteHTTPRequest(bot.BotSetting.Client, req)
if err != nil {
return nil, errors.Wrap(err, "Failed to executeHTTPRequest")
}
Expand Down Expand Up @@ -308,7 +308,7 @@ func (bot *Bot) apiRequest(ctx context.Context, endpoint string, data map[string
req.Header.Set("Content-Type", "application/json")
req.Header.Set("User-Agent", bot.UserAgent)

resp, err := libHttp.ExecuteHTTPRequest(bot.BotSetting.Client, req)
resp, err := httpclient.ExecuteHTTPRequest(bot.BotSetting.Client, req)
if err != nil {
return nil, errors.Wrap(err, "Failed to executeHTTPRequest")
}
Expand Down
10 changes: 5 additions & 5 deletions lib/misskey/bot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/cockroachdb/errors"

"hato-bot-go/lib"
libHttp "hato-bot-go/lib/http"
"hato-bot-go/lib/httpclient"
"hato-bot-go/lib/misskey"
)

Expand All @@ -32,7 +32,7 @@ func TestAddReaction(t *testing.T) {
noteID: "note456",
reaction: "❤️",
statusCode: http.StatusBadRequest,
expectError: libHttp.ErrHTTPRequestError,
expectError: httpclient.ErrHTTPRequestError,
},
}

Expand Down Expand Up @@ -101,7 +101,7 @@ func TestCreateNote(t *testing.T) {
},
statusCode: http.StatusBadRequest,
responseBody: `{"error":"bad request"}`,
expectError: libHttp.ErrHTTPRequestError,
expectError: httpclient.ErrHTTPRequestError,
},
// jscpd:ignore-end
}
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestUploadFile(t *testing.T) {
readerData: "test content",
statusCode: http.StatusBadRequest,
responseBody: `{"error":"bad request"}`,
expectError: libHttp.ErrHTTPRequestError,
expectError: httpclient.ErrHTTPRequestError,
},
// jscpd:ignore-end
}
Expand All @@ -155,7 +155,7 @@ func TestUploadFile(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
t.Helper()
mockClient := libHttp.NewMockHTTPClient(tt.statusCode, tt.responseBody)
mockClient := httpclient.NewMockHTTPClient(tt.statusCode, tt.responseBody)
bot := misskey.NewBotWithClient(&misskey.BotSetting{
Domain: "example.com",
Token: "token",
Expand Down
4 changes: 2 additions & 2 deletions lib/misskey/misskey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/cockroachdb/errors"
"github.com/google/go-cmp/cmp"

"hato-bot-go/lib/http"
"hato-bot-go/lib/httpclient"
"hato-bot-go/lib/misskey"
)

Expand Down Expand Up @@ -113,7 +113,7 @@ func runSimpleBotTest(t *testing.T, req *runSimpleBotTestParams) {
// runBotTest HTTPクライアントのモック付きでボットテストを実行する共通ヘルパー
func runBotTest(t *testing.T, req *runBotTestParams) {
t.Helper()
mockClient := http.NewMockHTTPClient(req.StatusCode, req.ResponseBody)
mockClient := httpclient.NewMockHTTPClient(req.StatusCode, req.ResponseBody)
bot := misskey.NewBotWithClient(&misskey.BotSetting{
Domain: "example.com",
Token: "token",
Expand Down
9 changes: 9 additions & 0 deletions scripts/build/update_go_version/update_go_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@ set -e
action="$(yq '.jobs.pr-super-lint.steps[-1].uses | line_comment' .github/workflows/pr-test.yml)"
go_version=$(docker run --rm --entrypoint '' "ghcr.io/super-linter/super-linter:slim-${action}" /bin/sh -c 'go version' | sed -e 's/^go version go\([0-9.]*\) .*$/\1/g')
sed -i -e "s/^go \([0-9.]*\)/go $go_version/g" go.mod
image_tag=$(grep golang Dockerfile | sed -e 's/FROM \(golang:[^@]*\).*$/\1/g')
new_image_tag=${image_tag//[0-9.]*-/$go_version-}

if [ "$image_tag" = "$new_image_tag" ]; then
exit
fi

digest=$(docker buildx imagetools inspect "$new_image_tag" --format '{{json .Manifest.Digest}}' | tr -d '"')
sed -i -e "s/FROM $image_tag@sha256:[^ ]*/FROM $new_image_tag@$digest/g" Dockerfile