mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-22 13:55:07 -05:00
API: Allow setting the issue number when creating an issue #3749
Closed
opened 2025-11-02 05:24:01 -06:00 by GiteaMirror
·
17 comments
No Branch/Tag Specified
main
release/v1.25
release/v1.24
release/v1.23
release/v1.22
release/v1.21
release/v1.20
release/v1.19
release/v1.18
release/v1.17
release/v1.16
release/v1.15
release/v1.14
release/v1.13
release/v1.12
release/v1.11
release/v1.10
release/v1.9
release/v1.8
v1.25.3
v1.25.2
v1.25.1
v1.25.0
v1.24.7
v1.25.0-rc0
v1.26.0-dev
v1.24.6
v1.24.5
v1.24.4
v1.24.3
v1.24.2
v1.24.1
v1.24.0
v1.23.8
v1.24.0-rc0
v1.25.0-dev
v1.23.7
v1.23.6
v1.23.5
v1.23.4
v1.23.3
v1.23.2
v1.23.1
v1.23.0
v1.23.0-rc0
v1.24.0-dev
v1.22.6
v1.22.5
v1.22.4
v1.22.3
v1.22.2
v1.22.1
v1.22.0
v1.23.0-dev
v1.22.0-rc1
v1.21.11
v1.22.0-rc0
v1.21.10
v1.21.9
v1.21.8
v1.21.7
v1.21.6
v1.21.5
v1.21.4
v1.21.3
v1.21.2
v1.20.6
v1.21.1
v1.21.0
v1.21.0-rc2
v1.21.0-rc1
v1.20.5
v1.22.0-dev
v1.21.0-rc0
v1.20.4
v1.20.3
v1.20.2
v1.20.1
v1.20.0
v1.19.4
v1.21.0-dev
v1.20.0-rc2
v1.20.0-rc1
v1.20.0-rc0
v1.19.3
v1.19.2
v1.19.1
v1.19.0
v1.19.0-rc1
v1.20.0-dev
v1.19.0-rc0
v1.18.5
v1.18.4
v1.18.3
v1.18.2
v1.18.1
v1.18.0
v1.17.4
v1.18.0-rc1
v1.19.0-dev
v1.18.0-rc0
v1.17.3
v1.17.2
v1.17.1
v1.17.0
v1.17.0-rc2
v1.16.9
v1.17.0-rc1
v1.18.0-dev
v1.16.8
v1.16.7
v1.16.6
v1.16.5
v1.16.4
v1.16.3
v1.16.2
v1.16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0-rc1
v1.3.2
v1.3.1
v1.3.0
v1.3.0-rc2
v1.3.0-rc1
v1.2.3
v1.2.2
v1.2.1
v1.2.0
v1.2.0-rc3
v1.2.0-rc2
v1.1.4
v1.2.0-rc1
v1.1.3
v1.1.2
v1.1.1
v1.1.0
v1.0.2
v1.0.1
v1.0.0
v0.9.99
Labels
Clear labels
$20
$250
$50
$500
backport/done
💎 Bounty
docs-update-needed
good first issue
hacktoberfest
issue/bounty
issue/confirmed
issue/critical
issue/duplicate
issue/needs-feedback
issue/not-a-bug
issue/regression
issue/stale
issue/workaround
lgtm/need 2
modifies/api
modifies/translation
outdated/backport/v1.18
outdated/theme/markdown
outdated/theme/timetracker
performance/bigrepo
performance/cpu
performance/memory
performance/speed
pr/breaking
proposal/accepted
proposal/rejected
pr/wip
pull-request
reviewed/wontfix
💰 Rewarded
skip-changelog
status/blocked
topic/accessibility
topic/api
topic/authentication
topic/build
topic/code-linting
topic/commit-signing
topic/content-rendering
topic/deployment
topic/distribution
topic/federation
topic/gitea-actions
topic/issues
topic/lfs
topic/mobile
topic/moderation
topic/packages
topic/pr
topic/projects
topic/repo
topic/repo-migration
topic/security
topic/theme
topic/ui
topic/ui-interaction
topic/ux
topic/webhooks
topic/wiki
type/bug
type/deprecation
type/docs
type/enhancement
type/feature
type/miscellaneous
type/proposal
type/question
type/refactoring
type/summary
type/testing
type/upstream
Mirrored from GitHub Pull Request
Milestone
No items
No Milestone
Projects
Clear projects
No project
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/gitea#3749
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @argv-minus-one on GitHub (Aug 7, 2019).
[x]):Description
Please allow creating issues through the API (
POST /api/v1/repos/{user}/{repository}/issues) with a specific issue number/index. This would allow importing issues from other issue trackers while preserving their issue numbers.Workaround
This can also be accomplished by changing the database field directly, after the issue is created, using a query like:
…where the first parameter is the desired issue number, and the second parameter is the
idfield in the JSON response from creating the issue.@lunny commented on GitHub (Aug 8, 2019):
@argv-minus-one I think we should not do that. We have a migrations package https://github.com/go-gitea/gitea/tree/master/modules/migrations and we can migrate almost all data from github. Users can contribute this package and migrate via Gitea API.
@argv-minus-one commented on GitHub (Aug 8, 2019):
I see.
I'll take a look, but I'm not sure if I have time to learn Go and Gitea's internals right now. In the mean time, I've posted issue #7802 for my specific use-case, which is importing from Bugzilla.
@argv-minus-one commented on GitHub (Aug 9, 2019):
The migrations package seems designed for migrating Git repositories and associated data from GitHub-like sites, and would need a pretty major redesign to handle migrating anything else, such as issues from a separate issue tracker like Bugzilla.
@lunny commented on GitHub (Aug 9, 2019):
@argv-minus-one I never used bugzilla and I want to know why do you want a special issue number?
@argv-minus-one commented on GitHub (Aug 11, 2019):
I want to preserve the Bugzilla issue numbers when importing them into Gitea, because I have commit messages and emails that reference them by issue number (like “fixes #123” and “please look at bug 234”).
@guillep2k commented on GitHub (Aug 11, 2019):
This looks like a one-time procedure. I'd rather write a script to generate the
UPDATEinstructions while migrating and run it right after finishing the process. If you do this, remember to do it in strict descending order, otherwise you'll have ID number collisions. After that you need to update the corresponding row ID numbering sequence to at least max(id)+1 (in Postgres it's a sequence, in SQLite I don't know).@lafriks commented on GitHub (Aug 11, 2019):
I don't see how this could be implemented without breaking a lot of stuff imho
@jpicht commented on GitHub (Aug 11, 2019):
It could, by requiring that the override-issue-number be larger than every issue number already used for this repository. One should limit this ability to the repo owner, obviously.
@argv-minus-one commented on GitHub (Aug 13, 2019):
I don't see any sequence for the
indexcolumn (containing the issue number) in Postgres. When Gitea goes to create a new issue, it finds the next issue number using aSELECT MAX(`index`)query, rather than calling a sequence manipulation function. Neither Gitea nor the database seem to keep a stored “next issue number” anywhere. Please correct me if I'm wrong!What would break?
That would be fine for me, but out of curiosity, why not allow any unused issue number to be used? The database schema already contains a
UNIQUE INDEXnamedUQE_issue_repo_indexto ensure that all issues have a unique issue number.@guillep2k commented on GitHub (Aug 13, 2019):
If you see it from the point of view of your database, there might be no problems. But Gitea must support other database engines that won't play nicely with that kind of tinkering. For instance, Postgres uses sequences, while MS SQL Server and MySQL use auto-increment IDs. SQLite is used for light loads where a
select max(id)will probably be OK; but as soon as you add many users concurrently accessing the database, that kind of strategy breaks rapidly (it's either long standing table locks or ID collision).It's pretty buried in the docs, but SQLite is suggested only for tiny installations.
@argv-minus-one commented on GitHub (Aug 13, 2019):
I see. Well, Gitea contains a
SELECT MAXquery here, which is called from here when creating a new issue, to decide what the new issue number will be. It does not appear to care which database is in use. If this is a performance problem, then perhaps it should be reported?Anyway, I threw together a Gitea instance on PostgreSQL, then tried creating an issue, increasing its issue number (from #1 to #2) with an
UPDATE, then creating another issue. It creates the second issue without complaint and makes it #3, same as on SQLite. So, that doesn't seem to break.Is there anything else that might break when I do this?
Note, by the way, that the
issuetable contains two auto-increment-like columns:idandindex.idis globally unique, and is a normal auto-increment column.indexis unique only for a single repository, and starts at 1 for each repository (that is, each repo's first issue is #1, its second issue is #2, and so on).Normal database auto-increment can't be used for this. PostgreSQL sequences don't seem up to the task, either, unless Gitea were to
CREATE SEQUENCEfor every single repo on the site (that is, oneCREATE SEQUENCEfor each row in therepositorytable).I only know of two ways to deal with this: something along the lines of
SELECT MAXorSELECT … ORDER BY … LIMIT 1, or by querying and immediately updating a column in therepositorytable for the next issue number (which may not be any faster).PostgreSQL seems to prefer
SELECT … ORDER BY … LIMIT 1, by the way.EXPLAIN ANALYZE SELECT MAX(index) FROM issue WHERE repo_id = 1yields this:Whereas
EXPLAIN ANALYZE SELECT index FROM issue WHERE repo_id = 1 ORDER BY index DESC LIMIT 1yields:If I'm reading this right, PostgreSQL answers a
SELECT MAXquery on an indexed column by scanning the entire index, rather than just fetching the highest value from the index as withSELECT … ORDER BY … LIMIT 1. The actual execution time is slightly faster, but I have only one repo with two issues, so I have no idea how these queries perform on a real-world Gitea database.@guillep2k commented on GitHub (Aug 13, 2019):
@argv-minus-one You are exactly right, as I was getting confused with the
IDproperty which is in fact auto-incremented, but theindexis not, apparently. I'm sorry about that.@jpicht commented on GitHub (Aug 13, 2019):
If somebody deleted some issues, for whatever reason, there might be commits referencing the issue. If somebody recycled that issue number, it could become very confusing fast.
So as your use case does not require for them to be inserted out-of-order, this could be a reasonable restriction.
Btw. temporarily creating issues with the desired index - 1 in the database while importing the issues from bugzilla would result in them being created with the same issue number. It's a dirty hack, but it would work.
@lunny commented on GitHub (Aug 14, 2019):
@jpicht so gitea haven't support deleting issues yet.
As I said above, it could be implemented to satisfy migrations
Downloaderinterface with some small changes.@guillep2k commented on GitHub (Aug 14, 2019):
@lunny Want me to take a look into it?
@lunny commented on GitHub (Aug 14, 2019):
@guillep2k Yes, please feel free to do that.
@wxiaoguang commented on GitHub (May 9, 2023):
It doesn't seem a general/feasible solution.
The proper solution would be using a separate mapping table or a separate field.