Auto-link commits, branches, and PRs to issues via post-receive hook (SZ-122)
rk@tigase.net opened 3 days ago

Summary

Automatically link commits, branches, and PRs to Sztab issues when an issue key appears in a commit message, branch name, or PR title. Eliminates manual traceability workarounds and makes Sztab's repository and project management layers first-class citizens of each other.

Motivation

Raised by Wojciech: inter-item linking (commits ↔ issues ↔ PRs) is a core feature of serious project management software. OneDev had it and removed it for no good reason. Sztab will have it from the start.

Issue key format

Canonical Sztab key: SZTaa00001 (two lowercase project-code letters + 5 digits) Regex: SZT[a-z]{2}\d{5}

Acceptance criteria

  •  post-receive hook installed on repo creation
  •  Hook fires on every push and calls Sztabina internal endpoint
  •  Commit messages and branch names parsed for SZT[a-z]{2}\d{5}
  •  Links persisted with duplicate guard
  •  Issue view shows linked commits and PRs
  •  PR view shows linked issue badge
  •  Manual link from issue UI works
  •  Existing repos migrated via hook install script
  •  No regressions to push, PR, or issue workflows
  • rk@tigase.net commented 3 days ago

    Design

    Trigger: git post-receive hook

    • Installed into every bare repo under hooks/post-receive at creation time
    • One-line addition to RepoHandler.CreateRepo in Sztabina
    • Migration script installs hook into all existing repos
    • Hook reads stdin (oldSha newSha refName), fetches commit messages via git log, calls POST /internal/notify/push on Sztabina

    Sztabina: new internal endpoint

    • POST /internal/notify/push
    • Receives push data, extracts commits and branch name
    • Fires POST /api/internal/hooks/push on Spring backend

    Spring backend: IssueReferenceService

    • Parses issue keys from commit messages and branch name
    • Resolves keys to issue IDs via existing global key lookup
    • Persists to issue_references table
    • Duplicate guard: upsert on (issue_id, commit_sha, source_type)

    PR linking

    • On PR create/update: parse PR title for issue keys
    • Same IssueReferenceService, source_type = PR

    Manual linking

    • Issue UI: "Link" button → search/select issue → source_type = MANUAL

    New table: issue_references

    ColumnTypeNotes
    idbigserialPK
    issue_idbigintFK → issues
    project_idbigintFK → projects
    commit_shavarchar(40)nullable
    pr_idbigintFK → pull_requests, nullable
    source_typevarcharCOMMIT, BRANCH, PR, MANUAL
    ref_textvarcharraw key found e.g. SZTsz00121
    created_attimestamptz

    Visibility

    • Issue view: new "References" section showing:
      • Linked commits (sha, message, author, date)
      • Linked PRs (title, status, author)
    • PR view: linked issue badge in PR header

    Flyway migration

    • V16__add_issue_references.sql

    Out of scope

    • Automatic status transitions on PR merge — separate ticket, policy is complex
    • Commit detail page — follow-up
  • rk@tigase.net commented 3 days ago

    Task breakdown

    • post-receive hook script + install on create: 2h
    • Sztabina /internal/notify/push endpoint: 3h
    • Spring IssueReferenceService + V16 migration: 4h
    • PR title parsing on create/update: 2h
    • Issue view References section (frontend): 6h
    • PR view linked issue badge (frontend): 2h
    • Manual link UI: 3h
    • Existing repo migration script: 1h
    • Testing + regression: 1h
  • Wojciech Kapcia (Tigase) commented 2 days ago

    On 19/03/2026 21:23, rk@tigase.net wrote:

    I think this will be valuable - I recall you raised this before.

    Good memory, I don't remember mentioning it :)

    This is my approach to automatic commit <=> issue <=> PR linking using Sztabina push webhooks. Pl let me know if I am overcomplicating:

    • On every push, Sztabina fires a webhook to the backend
    • Commit messages and branch names are parsed for Sztab issue keys (SZTaa00001 format)
    • Matching issues are automatically linked and shown in the issue view
    • PR titles are also parsed on creation/update
    • Manual linking from the issue UI as a fallback

    Thoughts?

    Seems about right.

    One problem I see is matching the issues from the commit message - over the years we used so many systems that the issue format differed a lot from one to another: from the base #<issue_number> to #<[short-]project-ID>-number to full-blown#-issue-id (e.g. #tigase/_clients/beagle-im#654 or #SZ-122 or #122 )

    Sztab will probably have its own ID system so we should think how (if we want past commits association) do that.

    Ps: Why not take it a step further with automatic issue status transitions driven by PR state transitions: if a PR title references an issue key and the PR is merged, the issue automatically transitions to RESOLVED. keywords — for example, a commit message containing "fixes SZTsz00121" would automatically move that issue to RESOLVED via the existing state machine. Conversely, when the PR is reopened (APPROVED => IN PROGRESS), the issue goes from R -> O. But this gets complicated as there could be more than one PR addressing an issue - Dobra, nie mieszam, bo się jeszcze zsiądzie.

    Some systems do that though, to be honest, I never used that nor was convinced by it. I guess one of the reasons is/was because Tigase is quite modular and quite often you had to make changes in multiple repositories then changes from one could trigger issue state while not finally fixing something. But it could be usefull.

issue 1 of 1
Type
New Feature
Priority
Normal
Assignee
Version
1.10.0
Sprints
n/a
Customer
n/a
Issue Votes (0)
Watchers (3)
Reference
SZ-122
Please wait...
Page is in error, reload to recover