Skip to content

Issue1524 CreateGameCreatorCustomJobsの実装#1542

Open
ebisen14441444 wants to merge 5 commits into
mainfrom
issue1524
Open

Issue1524 CreateGameCreatorCustomJobsの実装#1542
ebisen14441444 wants to merge 5 commits into
mainfrom
issue1524

Conversation

@ebisen14441444
Copy link
Copy Markdown
Contributor

@ebisen14441444 ebisen14441444 commented Apr 9, 2026

Summary by CodeRabbit

リリースノート

  • バグ修正

    • カスタムジョブの作成処理を実装し、実際に永続化されるようになりました。空のジョブリストは影響なく処理され、存在しない参照先がある場合はエラーとなります。
  • テスト

    • カスタムジョブ作成機能の自動テストを追加(成功ケース、空入力、無効参照の検証)。

@ebisen14441444 ebisen14441444 requested a review from a team as a code owner April 9, 2026 13:04
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 9, 2026

Migrate lint ✅

Lint output

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a32ab540-fcae-4039-9106-c9acc335379b

📥 Commits

Reviewing files that changed from the base of the PR and between a975636 and 4e5aec1.

📒 Files selected for processing (2)
  • src/repository/gorm2/game_creator.go
  • src/repository/gorm2/game_creator_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/repository/gorm2/game_creator.go
  • src/repository/gorm2/game_creator_test.go

📝 Walkthrough

Walkthrough

CreateGameCreatorCustomJobs をスタブから実装へ差し替え。空スライスは no-op、ドメイン構造体をスキーマレコードへ変換して DB に一括作成し、DB取得および作成エラーをラップして返す。対応する統合テストを追加。

Changes

Cohort / File(s) Summary
GameCreator リポジトリ実装
src/repository/gorm2/game_creator.go
CreateGameCreatorCustomJobs(ctx, jobs) を実装:空スライスは早期 return、gc.db.getDB(ctx) で DB ハンドル取得、domain.GameCreatorCustomJobschema.GameCreatorCustomJobTable にマッピングして db.Create(&customJobs).Error で永続化、DB取得/作成失敗時にエラーを返す。
テストスイート追加
src/repository/gorm2/game_creator_test.go
TestCreateGameCreatorCustomJobs を追加:複数ジョブ挿入成功、空スライス no-op、存在しない game_id による失敗のケースをテーブル駆動で検証し、挿入結果とフィールドを確認・クリーンアップする統合テストを実装。

Sequence Diagram(s)

sequenceDiagram
    participant Test as テスト
    participant Repo as GameCreator リポジトリ
    participant DB as データベース
    participant Schema as スキーマ変換

    Test->>Repo: CreateGameCreatorCustomJobs(ctx, jobs)
    Repo->>DB: gc.db.getDB(ctx)
    DB-->>Repo: db handle / error
    alt db handle
        Repo->>Schema: domain jobs を schema レコードに変換
        Schema-->>Repo: schema レコードリスト
        Repo->>DB: db.Create(&customJobs)
        DB-->>Repo: success / error
        Repo-->>Test: return nil / error
    else error
        Repo-->>Test: return fmt.Errorf("get db: %w", err)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 分

Possibly related PRs

Suggested labels

Review effort 3/5

Suggested reviewers

  • mathsuky
  • ikura-hamu
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed プルリクエストのタイトルは「Issue1524 CreateGameCreatorCustomJobsの実装」であり、変更内容(CreateGameCreatorCustomJobs メソッドの実装)と直接対応しており、明確かつ具体的に主要な変更を要約しています。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue1524

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 9, 2026

Codecov Report

❌ Patch coverage is 88.88889% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.10%. Comparing base (4bf5912) to head (4e5aec1).

Files with missing lines Patch % Lines
src/repository/gorm2/game_creator.go 88.88% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1542      +/-   ##
==========================================
+ Coverage   52.03%   52.10%   +0.07%     
==========================================
  Files         143      143              
  Lines       10689    10705      +16     
==========================================
+ Hits         5562     5578      +16     
+ Misses       4800     4799       -1     
- Partials      327      328       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/repository/gorm2/game_creator_test.go`:
- Around line 561-565: The test case "空配列を渡してもエラーにならない" currently returns early
on len(jobIDs)==0 and only asserts no error; update that test in
game_creator_test.go to capture the DB row count for the relevant table (e.g.,
via the repository or gorm DB used in tests) before calling the method under
test, call the function as before, then re-query the row count after and assert
the counts are equal (no new rows inserted); apply the same pattern to the other
similar cases mentioned (around the other tests referencing empty job slices and
jobIDs).

In `@src/repository/gorm2/game_creator.go`:
- Around line 127-131: In CreateGameCreatorCustomJobs, move the early-return
check for empty input before calling gc.db.getDB(ctx): if len(jobs) == 0 {
return nil }, so noop calls do not attempt to open the DB via gc.db.getDB(ctx);
apply the same change to the other similar function in this file that takes jobs
(the second Create... method around the later block) so both short-circuit on
empty jobs before any DB access.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 48e2d532-d847-4a04-a931-a85a3ad5fe4c

📥 Commits

Reviewing files that changed from the base of the PR and between 4bf5912 and 826e964.

📒 Files selected for processing (2)
  • src/repository/gorm2/game_creator.go
  • src/repository/gorm2/game_creator_test.go

Comment thread src/repository/gorm2/game_creator_test.go
Comment on lines +127 to +131
func (gc *GameCreator) CreateGameCreatorCustomJobs(ctx context.Context, jobs []*domain.GameCreatorCustomJob) error {
db, err := gc.db.getDB(ctx)
if err != nil {
return fmt.Errorf("get db: %w", err)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

空入力の早期 return を DB 取得より前に移動してください。

jobs が空でも先に gc.db.getDB(ctx) を呼んでいるため、no-op で終わるべき呼び出しが DB 状態に依存して失敗し得ます。len(jobs) == 0 を先に判定して戻す方が安全です。

💡 修正案
func (gc *GameCreator) CreateGameCreatorCustomJobs(ctx context.Context, jobs []*domain.GameCreatorCustomJob) error {
+	if len(jobs) == 0 {
+		return nil
+	}
+
	db, err := gc.db.getDB(ctx)
	if err != nil {
		return fmt.Errorf("get db: %w", err)
	}

	customJobs := make([]schema.GameCreatorCustomJobTable, 0, len(jobs))
	for _, job := range jobs {
		customJobs = append(customJobs, schema.GameCreatorCustomJobTable{
			ID:          uuid.UUID(job.GetID()),
			GameID:      uuid.UUID(job.GetGameID()),
			DisplayName: string(job.GetDisplayName()),
			CreatedAt:   job.GetCreatedAt(),
		})
	}

-	if len(customJobs) == 0 {
-		return nil
-	}
-
	err = db.Create(&customJobs).Error
	if err != nil {
		return fmt.Errorf("create custom jobs: %w", err)
	}

	return nil
}

Also applies to: 143-145

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/repository/gorm2/game_creator.go` around lines 127 - 131, In
CreateGameCreatorCustomJobs, move the early-return check for empty input before
calling gc.db.getDB(ctx): if len(jobs) == 0 { return nil }, so noop calls do not
attempt to open the DB via gc.db.getDB(ctx); apply the same change to the other
similar function in this file that takes jobs (the second Create... method
around the later block) so both short-circuit on empty jobs before any DB
access.

Copy link
Copy Markdown
Contributor

@mathsuky mathsuky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます!いくつかコメントしたのでご確認お願いいたします:bow-nya:

Comment on lines +148 to +150
if err != nil {
return fmt.Errorf("create custom jobs: %w", err)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repositoryパッケージにErrForeignKeyViolatedを定義してそれを使うようにするのが良いと思います。

Comment on lines +585 to +589
if len(jobIDs) == 0 {
err = db.Model(&schema.GameCreatorCustomJobTable{}).Where("id IN ?", jobIDs).Count(&beforeCount).Error
require.NoError(t, err)
require.Equal(t, int64(0), beforeCount, "テスト開始前に同じIDのカスタムジョブが存在しています")
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jobIDsの長さが0のケースでやっているので,beforeCountは常に0になるはずです。このブロックは不要なのでまるまる削除して良いと思います。
それに伴って,afterCountの方も削除して良いともいます。jobが空配列の時にエラーを返さないことはassert.NoError(t, err)で十分チェックできていると思います。

Comment on lines +609 to +619
if !testCase.verifyByID || len(jobIDs) == 0 {
if len(jobIDs) == 0 && !testCase.expectErr {
var afterCount int64
err = db.Model(&schema.GameCreatorCustomJobTable{}).
Where("game_id IN ?", []uuid.UUID{uuid.UUID(gameID1), uuid.UUID(gameID2)}).
Count(&afterCount).Error
require.NoError(t, err)
assert.Equal(t, beforeCount, afterCount)
}
return
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用意しているテストケースにおいて!testCase.verifyByID || len(jobIDs) == 0は常にtrueなので,この条件分岐は不要に思います。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants