From 8da27ea5123585b48f6176a16fc8d9d275152333 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Feb 2026 17:31:34 +0000 Subject: [PATCH] Use octicon-git-pull-request-draft for both WIP timeline entries Co-authored-by: silverwind <115237+silverwind@users.noreply.github.com> --- services/issue/title_test.go | 97 +++++++++++++++++++ .../repo/issue/view_content/comments.tmpl | 4 +- 2 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 services/issue/title_test.go diff --git a/services/issue/title_test.go b/services/issue/title_test.go new file mode 100644 index 00000000000..73cd670988b --- /dev/null +++ b/services/issue/title_test.go @@ -0,0 +1,97 @@ +// Copyright 2026 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package issue + +import ( + "testing" + + issues_model "code.gitea.io/gitea/models/issues" + "code.gitea.io/gitea/models/unittest" + user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/setting" + + "github.com/stretchr/testify/assert" +) + +func TestChangeTitleWIPPrefix(t *testing.T) { + assert.NoError(t, unittest.PrepareTestDatabase()) + + // Load a pull request + pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1}) + assert.NoError(t, pr.LoadIssue(t.Context())) + issue := pr.Issue + + // Load repo and doer + assert.NoError(t, issue.LoadRepo(t.Context())) + doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: issue.Repo.OwnerID}) + + // Get the WIP prefix from settings + wipPrefix := setting.Repository.PullRequest.WorkInProgressPrefixes[0] + + // Store original title + originalTitle := issue.Title + wipTitle := wipPrefix + " " + originalTitle + + // Test 1: Add WIP prefix + err := ChangeTitle(t.Context(), issue, doer, wipTitle) + assert.NoError(t, err) + + // Check that a comment was created with the correct type + comments, err := issues_model.FindComments(t.Context(), &issues_model.FindCommentsOptions{ + IssueID: issue.ID, + Type: issues_model.CommentTypeMarkedAsWorkInProgress, + }) + assert.NoError(t, err) + assert.Len(t, comments, 1, "Should have created a CommentTypeMarkedAsWorkInProgress comment") + + // Test 2: Remove WIP prefix + err = ChangeTitle(t.Context(), issue, doer, originalTitle) + assert.NoError(t, err) + + // Check that a comment was created with the correct type + comments, err = issues_model.FindComments(t.Context(), &issues_model.FindCommentsOptions{ + IssueID: issue.ID, + Type: issues_model.CommentTypeMarkedAsReadyForReview, + }) + assert.NoError(t, err) + assert.Len(t, comments, 1, "Should have created a CommentTypeMarkedAsReadyForReview comment") +} + +func TestChangeTitleNormalChange(t *testing.T) { + assert.NoError(t, unittest.PrepareTestDatabase()) + + // Load a pull request + pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1}) + assert.NoError(t, pr.LoadIssue(t.Context())) + issue := pr.Issue + + // Load repo and doer + assert.NoError(t, issue.LoadRepo(t.Context())) + doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: issue.Repo.OwnerID}) + + // Store original title + originalTitle := issue.Title + newTitle := "New title without WIP" + + // Ensure neither title has WIP prefix + assert.False(t, issues_model.HasWorkInProgressPrefix(originalTitle)) + assert.False(t, issues_model.HasWorkInProgressPrefix(newTitle)) + + // Change title + err := ChangeTitle(t.Context(), issue, doer, newTitle) + assert.NoError(t, err) + + // Check that a normal change title comment was created + comments, err := issues_model.FindComments(t.Context(), &issues_model.FindCommentsOptions{ + IssueID: issue.ID, + Type: issues_model.CommentTypeChangeTitle, + }) + assert.NoError(t, err) + assert.Greater(t, len(comments), 0, "Should have created a CommentTypeChangeTitle comment") + + // Verify the last comment has the correct old and new titles + lastComment := comments[len(comments)-1] + assert.Equal(t, originalTitle, lastComment.OldTitle) + assert.Equal(t, newTitle, lastComment.NewTitle) +} diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 06e8efc318f..69dc4992c25 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -695,7 +695,7 @@ {{else if eq .Type 39}}