Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ prime/
/.goosehints
/.windsurfrules
/.github/copilot-instructions.md
/AGENT.md
/CLAUDE.md
/llms.txt

# Ignore worktrees when working on multiple branches
Expand Down
8 changes: 5 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Instructions for agents

- Use `make help` to find available development targets
- Use the latest Golang stable release when working on Go code
- Use the latest Node.js LTS release when working on TypeScript code
- Before committing `.go` changes, run `make fmt` to format, and run `make lint-go` to lint
- Install the latest `go` stable release before working on `.go` files
Comment thread
silverwind marked this conversation as resolved.
Outdated
- Install the latest `node` LTS release and `pnpm` before working on `.ts` files
Comment thread
silverwind marked this conversation as resolved.
Outdated
- Before running `.go` tests, run `make deps-backend` to install dependencies
- Before running `.ts` tests, run `make deps-frontend` to install dependencies
- Before committing `.go`, run `make fmt` to format, and run `make lint-go` to lint
- Before committing `.ts` changes, run `make lint-js` to lint
- Before committing `go.mod` changes, run `make tidy`
- Before committing new `.go` files, add the current year into the copyright header
Expand Down
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@AGENTS.md
5 changes: 5 additions & 0 deletions models/issues/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ const (
CommentTypeUnpin // 37 unpin Issue/PullRequest

CommentTypeChangeTimeEstimate // 38 Change time estimate

CommentTypeMarkedAsWorkInProgress // 39 Mark PR as work in progress
CommentTypeMarkedAsReadyForReview // 40 Mark PR as ready for review
)

var commentStrings = []string{
Expand Down Expand Up @@ -158,6 +161,8 @@ var commentStrings = []string{
"pin",
"unpin",
"change_time_estimate",
"marked_as_work_in_progress",
"marked_as_ready_for_review",
}

func (t CommentType) String() string {
Expand Down
17 changes: 16 additions & 1 deletion models/issues/issue_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,23 @@ func ChangeIssueTitle(ctx context.Context, issue *Issue, doer *user_model.User,
return fmt.Errorf("loadRepo: %w", err)
}

// Determine the comment type based on WIP prefix changes for pull requests
commentType := CommentTypeChangeTitle
if issue.IsPull {
hadWIP := HasWorkInProgressPrefix(oldTitle)
hasWIP := HasWorkInProgressPrefix(issue.Title)

if !hadWIP && hasWIP {
// WIP prefix was added
commentType = CommentTypeMarkedAsWorkInProgress
} else if hadWIP && !hasWIP {
// WIP prefix was removed
commentType = CommentTypeMarkedAsReadyForReview
Comment thread
wxiaoguang marked this conversation as resolved.
Outdated
}
}

opts := &CreateCommentOptions{
Type: CommentTypeChangeTitle,
Type: commentType,
Doer: doer,
Repo: issue.Repo,
Issue: issue,
Expand Down
2 changes: 2 additions & 0 deletions options/locale/locale_en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -1778,6 +1778,8 @@
"repo.pulls.title_desc": "wants to merge %[1]d commits from <code>%[2]s</code> into <code id=\"branch_target\">%[3]s</code>",
"repo.pulls.merged_title_desc": "merged %[1]d commits from <code>%[2]s</code> into <code>%[3]s</code> %[4]s",
"repo.pulls.change_target_branch_at": "changed target branch from <b>%s</b> to <b>%s</b> %s",
"repo.pulls.marked_as_work_in_progress": "marked the pull request as work in progress %s",
"repo.pulls.marked_as_ready_for_review": "marked the pull request as ready for review %s",
"repo.pulls.tab_conversation": "Conversation",
"repo.pulls.tab_commits": "Commits",
"repo.pulls.tab_files": "Files Changed",
Expand Down
97 changes: 97 additions & 0 deletions services/issue/title_test.go
Original file line number Diff line number Diff line change
@@ -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.NotEmpty(t, comments, "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)
}
21 changes: 20 additions & 1 deletion templates/repo/issue/view_content/comments.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
29 = PULL_PUSH_EVENT, 30 = PROJECT_CHANGED, 31 = PROJECT_BOARD_CHANGED
32 = DISMISSED_REVIEW, 33 = COMMENT_TYPE_CHANGE_ISSUE_REF, 34 = PR_SCHEDULE_TO_AUTO_MERGE,
35 = CANCEL_SCHEDULED_AUTO_MERGE_PR, 36 = PIN_ISSUE, 37 = UNPIN_ISSUE,
38 = COMMENT_TYPE_CHANGE_TIME_ESTIMATE -->
38 = COMMENT_TYPE_CHANGE_TIME_ESTIMATE, 39 = MARKED_AS_WORK_IN_PROGRESS,
40 = MARKED_AS_READY_FOR_REVIEW -->
{{if eq .Type 0}}
<div class="timeline-item comment" id="{{.HashTag}}">
{{if .OriginalAuthor}}
Expand Down Expand Up @@ -692,6 +693,24 @@
{{end}}
</span>
</div>
{{else if eq .Type 39}}
<div class="timeline-item event" id="{{.HashTag}}">
<span class="badge">{{svg "octicon-git-pull-request-draft"}}</span>
{{template "shared/user/avatarlink" dict "user" .Poster}}
<span class="comment-text-line">
{{template "shared/user/authorlink" .Poster}}
{{ctx.Locale.Tr "repo.pulls.marked_as_work_in_progress" $createdStr}}
</span>
</div>
{{else if eq .Type 40}}
<div class="timeline-item event" id="{{.HashTag}}">
<span class="badge">{{svg "octicon-eye"}}</span>
{{template "shared/user/avatarlink" dict "user" .Poster}}
<span class="comment-text-line">
{{template "shared/user/authorlink" .Poster}}
{{ctx.Locale.Tr "repo.pulls.marked_as_ready_for_review" $createdStr}}
</span>
</div>
{{end}}
{{end}}
{{end}}