Files
gitea-tea/internal/services/draft.go
T
bircni 12e415a7a7 refactor: add services layer on the Gitea Go SDK (#1125)
- `internal/services`: typed Gitea workflows built on `gitea.dev/sdk`, independent of CLI flags and terminal I/O: issues, pull requests, reviews, comments, labels, milestones, releases and assets, repositories, branches, wiki, Actions (workflows, runs, jobs, logs, artifacts, secrets, variables), organizations, teams, webhooks, notifications, SSH keys, tracked time, admin users, search and status.
- SDK types are mapped to tea's own output types, so `--json` stays a stable contract. Requests the SDK cannot express yet (e.g. pull list filters, multi-status run lists, org label archiving) go through small raw helpers, each marked `TODO(sdk)` with the missing SDK piece.
- Targets Gitea 28 or newer: no version or API-schema probing. List helpers fill pages capped by `MAX_RESPONSE_ITEMS`.

Nothing imports this package yet.

Reviewed-on: https://gitea.com/gitea/tea/pulls/1125
Reviewed-by: TheFox0x7 <95654+thefox0x7@noreply.gitea.com>
2026-10-11 17:15:41 +00:00

32 lines
1001 B
Go

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package services
import "regexp"
// draftPrefixRe matches the prefixes Gitea recognizes as marking a pull
// request as a draft: a leading "WIP:" or "[WIP]" (case-insensitive),
// followed by any whitespace.
var draftPrefixRe = regexp.MustCompile(`(?i)^(wip:\s*|\[wip\]\s*)`)
// hasDraftPrefix reports whether title already starts with a draft marker.
func hasDraftPrefix(title string) bool {
return draftPrefixRe.MatchString(title)
}
// AddDraftPrefix returns title with a "WIP: " prefix, or title unchanged
// if it already carries a recognized draft prefix.
func AddDraftPrefix(title string) string {
if hasDraftPrefix(title) {
return title
}
return "WIP: " + title
}
// StripDraftPrefix returns title with any recognized leading draft prefix
// removed, or title unchanged if no prefix is present.
func StripDraftPrefix(title string) string {
return draftPrefixRe.ReplaceAllString(title, "")
}