Skip to content

Filter self-referencing commit comments from PR timeline#5

Closed
Copilot wants to merge 15 commits intomainfrom
copilot/fix-issue-36488
Closed

Filter self-referencing commit comments from PR timeline#5
Copilot wants to merge 15 commits intomainfrom
copilot/fix-issue-36488

Conversation

Copy link
Copy Markdown

Copilot AI commented Jan 30, 2026

When a PR is merged with a commit message containing the PR number (e.g., "Fix bug (go-gitea#123)"), Gitea creates a redundant "referenced this issue from a commit" timeline entry. This PR prevents these self-references from appearing in the timeline, matching GitHub's behavior.

Changes Made

  • Added isSelfReference() helper function in services/issue/commit.go that checks if a commit is the merge commit of the PR it references
  • Modified UpdateIssuesCommit() to call isSelfReference() before creating CommitRef comments
    • Checks if the referenced issue is a pull request
    • Loads PR data with proper error handling (uses IsErrPullRequestNotExist)
    • Compares commit SHA with the PR's MergedCommitID
    • Skips creating the comment if they match (self-reference detected)
  • Added comprehensive test coverage with TestUpdateIssuesCommit_SelfReference that verifies:
    • PR merge commits that reference their own PR do not create self-referencing comments
    • Normal commits can still create references to other issues/PRs
    • Uses realistic Gitea merge message format

Implementation Details

The fix prevents self-referencing comments from being created at the data level in Go code, rather than filtering them at the display level in templates. This approach:

  • Keeps all template code unchanged
  • Is more efficient (prevents unnecessary database writes)
  • Is cleaner and more maintainable with the logic extracted into a dedicated function

Testing

  • ✅ All existing tests pass
  • ✅ New test case validates self-reference filtering
  • ✅ Backend builds successfully
  • ✅ Code follows Gitea's coding conventions

The solution was implemented based on maintainer feedback to handle this in Go code rather than templates, with additional refactoring to extract the check into a separate function for better code organization.

Original prompt

Fix @go-gitea/giteago-gitea/issues/36488


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 30, 2026 04:32
Co-authored-by: silverwind <115237+silverwind@users.noreply.github.com>
Co-authored-by: silverwind <115237+silverwind@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue 36488 in Gitea Filter self-referencing commit comments from PR timeline Jan 30, 2026
Copilot AI requested a review from silverwind January 30, 2026 04:38
@silverwind
Copy link
Copy Markdown
Owner

@copilot can you find a solution that fixes this in go code, leaving the template code unchanged?

Copilot AI and others added 3 commits January 30, 2026 04:46
- Revert template changes
- Add check in UpdateIssuesCommit to skip creating CommitRef comments when the commit is the merge commit of the PR it references
- This keeps template code unchanged as requested

Co-authored-by: silverwind <115237+silverwind@users.noreply.github.com>
- Add nil check for PullRequest to prevent potential panic
- Add comprehensive test case TestUpdateIssuesCommit_SelfReference
- Test verifies self-references are skipped while other references work
- All tests passing

Co-authored-by: silverwind <115237+silverwind@users.noreply.github.com>
- Use IsErrPullRequestNotExist for proper error handling
- Remove redundant nil check (guaranteed after successful load)
- Fix test to use different commit SHAs (realistic Git scenario)
- All tests still passing

Co-authored-by: silverwind <115237+silverwind@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Jan 30, 2026

@copilot can you find a solution that fixes this in go code, leaving the template code unchanged?

Done! The fix is now implemented in Go code at services/issue/commit.go, and the template remains unchanged. The solution prevents self-referencing CommitRef comments from being created when a PR merge commit references its own PR number. Added comprehensive test coverage as well. See commit 7ef4293.

Use realistic merge message format: "Merge pull request 'title' (#number) from branch into target"

Co-authored-by: silverwind <115237+silverwind@users.noreply.github.com>
Cleaned up redundant inline comments while keeping essential test-level documentation

Co-authored-by: silverwind <115237+silverwind@users.noreply.github.com>
Extract isSelfReference function to improve code organization and reusability

Co-authored-by: silverwind <115237+silverwind@users.noreply.github.com>
silverwind and others added 3 commits January 30, 2026 11:25
I verified the `.env.local` syntax added in
alecthomas/chroma#1197 works as expected.
Fix go-gitea#36483 

In git log/rev-list, the "..." syntax represents the symmetric
difference between two references, which is different from the meaning
of "..." in git diff (where it implies diffing from the merge base).

For listing PR commits, we must use `merge-base..head` to include only
the commits introduced by the head branch. Otherwise, commits newly
pushed to the base branch would also be included, which is incorrect.
silverwind and others added 2 commits January 30, 2026 19:42
`smtp.mydomain.test` is a real domain that resolves to something and
which is being connected to while running tests. Instead, use
[.test](https://en.wikipedia.org/wiki/.test) which is guaranteed to
never be registered on the internet, so all connections to it will fail
with NXDOMAIN dns error.
@silverwind silverwind closed this Jan 30, 2026
@silverwind silverwind deleted the copilot/fix-issue-36488 branch January 30, 2026 20:20
techknowlogick pushed a commit that referenced this pull request Jan 31, 2026
## Overview
This PR updates the Go toolchain version from `1.25.5` to `1.25.6` for
the Gitea project.

## Changes

### Toolchain Update
- **Go Toolchain**: Updated from `go1.25.5` to `go1.25.6`

This is a minor toolchain version bump that ensures the project uses the
latest patch release of Go 1.25.

## Security Improvements

While this PR primarily addresses the toolchain update, the project
maintains a strong security posture through:

### Current Security Measures
```log
Vulnerability #1: GO-2026-4342                                                                                                                                                                                                      
    Excessive CPU consumption when building archive index in archive/zip
  More info: https://pkg.go.dev/vuln/GO-2026-4342
  Standard library
    Found in: archive/zip@go1.25.5
    Fixed in: archive/zip@go1.25.6
    Example traces found:
      #1: modules/packages/nuget/metadata.go:217:25: nuget.ParseNuspecMetaData calls zip.Reader.Open                                                                                                                                

Vulnerability #2: GO-2026-4341
    Memory exhaustion in query parameter parsing in net/url
  More info: https://pkg.go.dev/vuln/GO-2026-4341
  Standard library
    Found in: net/url@go1.25.5
    Fixed in: net/url@go1.25.6
    Example traces found:
      #1: modules/storage/minio.go:284:34: storage.MinioStorage.URL calls url.ParseQuery                                                                                                                                            
      #2: routers/api/v1/repo/action.go:1640:29: repo.DownloadArtifactRaw calls url.URL.Query

Vulnerability #3: GO-2026-4340
    Handshake messages may be processed at the incorrect encryption level in
    crypto/tls
  More info: https://pkg.go.dev/vuln/GO-2026-4340
  Standard library
    Found in: crypto/tls@go1.25.5
    Fixed in: crypto/tls@go1.25.6
    Example traces found:
      #1: services/auth/source/ldap/source_search.go:129:25: ldap.dial calls ldap.Conn.StartTLS, which calls tls.Conn.Handshake                                                                                                     
      #2: modules/graceful/server.go:156:14: graceful.Server.Serve calls http.Server.Serve, which eventually calls tls.Conn.HandshakeContext
      #3: modules/lfs/content_store.go:132:27: lfs.hashingReader.Read calls tls.Conn.Read
      #4: modules/proxyprotocol/conn.go:91:21: proxyprotocol.Conn.Write calls tls.Conn.Write
      #5: modules/session/virtual.go:168:39: session.VirtualStore.Release calls couchbase.CouchbaseProvider.Exist, which eventually calls tls.Dial
      go-gitea#6: services/auth/source/ldap/source_search.go:120:22: ldap.dial calls ldap.DialTLS, which calls tls.DialWithDialer
      go-gitea#7: services/migrations/gogs.go:114:34: migrations.client calls http.Transport.RoundTrip, which eventually calls tls.Dialer.DialContext
```

## Breaking Changes
None expected. This is a minor toolchain patch update.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants