[Bug?] Invalid value stored into GITEA_PR_ID during pull request merge #4882

Open
opened 2025-11-02 06:06:05 -06:00 by GiteaMirror · 6 comments
Owner

Originally created by @mshgh on GitHub (Feb 18, 2020).

  • Gitea version (or commit ref): 1.11.1 (docker image)
  • Git version: not relevant
  • Operating system: not relevant
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:

Description

I have found that during a pull request merge there is available variable GITEA_PR_ID in the pre-receive hook. Value for it is taken from DB pull_request.id, but I believe there should be used pull_request.index column instead which contains pull request number as given repository sees it.
I checked the source code and when calling method FullPushingEnvironment at https://github.com/go-gitea/gitea/blob/release/v1.11/services/pull/merge.go#L321 instead of passing pr.ID I think there should be passed pr.Index

P.S. If this is not a bug, but intentional, can we add another variable e.g. GITEA_PR_NUM populated with pr.Index?

Originally created by @mshgh on GitHub (Feb 18, 2020). <!-- NOTE: If your issue is a security concern, please send an email to security@gitea.io instead of opening a public issue --> <!-- 1. Please speak English, this is the language all maintainers can speak and write. 2. Please ask questions or configuration/deploy problems on our Discord server (https://discord.gg/gitea) or forum (https://discourse.gitea.io). 3. Please take a moment to check that your issue doesn't already exist. 4. Please give all relevant information below for bug reports, because incomplete details will be handled as an invalid report. --> - Gitea version (or commit ref): 1.11.1 (docker image) - Git version: not relevant - Operating system: not relevant - Database (use `[x]`): - [ ] PostgreSQL - [x] MySQL - [ ] MSSQL - [ ] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [ ] No - [x] Not relevant - Log gist: ## Description I have found that during a pull request merge there is available variable GITEA_PR_ID in the pre-receive hook. Value for it is taken from DB `pull_request.id`, but I believe there should be used `pull_request.index` column instead which contains pull request number as given repository sees it. I checked the source code and when calling method `FullPushingEnvironment` at https://github.com/go-gitea/gitea/blob/release/v1.11/services/pull/merge.go#L321 instead of passing `pr.ID` I think there should be passed `pr.Index` P.S. If this is not a bug, but intentional, can we add another variable e.g. GITEA_PR_NUM populated with `pr.Index`?
GiteaMirror added the issue/confirmedtype/enhancement labels 2025-11-02 06:06:05 -06:00
Author
Owner

@lafriks commented on GitHub (Feb 18, 2020):

It is intentional for internal use PR index could be added as additional variable

@lafriks commented on GitHub (Feb 18, 2020): It is intentional for internal use PR index could be added as additional variable
Author
Owner

@zeripath commented on GitHub (Feb 19, 2020):

Please note: These environment variables do not represent a public API at present and we reserve the right to change the names and what is set without reservation.

Clearly as more people want to use hooks we need to define a public API for these.

We should discuss these in another issue.

I would not be averse to reporting the index - when it would be cheap to do so - but we need to think carefully about what is required and what we should be returning.

@zeripath commented on GitHub (Feb 19, 2020): Please note: These environment variables do not represent a public API at present and we reserve the right to change the names and what is set without reservation. Clearly as more people want to use hooks we need to define a public API for these. We should discuss these in another issue. I would not be averse to reporting the index - when it would be cheap to do so - but we need to think carefully about what is required and what we should be returning.
Author
Owner

@mshgh commented on GitHub (Feb 19, 2020):

Understand. Would you mind to link this issue with the other one where hooks API will be discussed?

@mshgh commented on GitHub (Feb 19, 2020): Understand. Would you mind to link this issue with the other one where hooks API will be discussed?
Author
Owner

@stale[bot] commented on GitHub (Apr 19, 2020):

This issue has been automatically marked as stale because it has not had recent activity. I am here to help clear issues left open even if solved or waiting for more insight. This issue will be closed if no further activity occurs during the next 2 weeks. If the issue is still valid just add a comment to keep it alive. Thank you for your contributions.

@stale[bot] commented on GitHub (Apr 19, 2020): This issue has been automatically marked as stale because it has not had recent activity. I am here to help clear issues left open even if solved or waiting for more insight. This issue will be closed if no further activity occurs during the next 2 weeks. If the issue is still valid just add a comment to keep it alive. Thank you for your contributions.
Author
Owner

@mshgh commented on GitHub (Apr 19, 2020):

It looks like there is no discussions happening. Can we agree on adding for now at least
GITEA_PR_NUM? As this is pretty useful and obvious piece of information to have for git-hooks.
This is simple and straightforward code change too.

I am fine if there is chosen different name and/or this is marked as internal and subject of change w/o notice.

@mshgh commented on GitHub (Apr 19, 2020): It looks like there is no discussions happening. Can we agree on adding for now at least **GITEA_PR_NUM**? As this is pretty useful and obvious piece of information to have for git-hooks. This is simple and straightforward code change too. I am fine if there is chosen different name and/or this is marked as internal and subject of change w/o notice.
Author
Owner

@stale[bot] commented on GitHub (Jun 20, 2020):

This issue has been automatically marked as stale because it has not had recent activity. I am here to help clear issues left open even if solved or waiting for more insight. This issue will be closed if no further activity occurs during the next 2 weeks. If the issue is still valid just add a comment to keep it alive. Thank you for your contributions.

@stale[bot] commented on GitHub (Jun 20, 2020): This issue has been automatically marked as stale because it has not had recent activity. I am here to help clear issues left open even if solved or waiting for more insight. This issue will be closed if no further activity occurs during the next 2 weeks. If the issue is still valid just add a comment to keep it alive. Thank you for your contributions.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#4882