You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

199 lines
9.1 KiB

  1. ---
  2. date: "2019-11-21T17:00:00-03:00"
  3. title: "Usage: Automatically Linked References"
  4. slug: "automatically-linked-references"
  5. weight: 15
  6. toc: true
  7. draft: false
  8. menu:
  9. sidebar:
  10. parent: "usage"
  11. name: "Automatically Linked References"
  12. weight: 15
  13. identifier: "automatically-linked-references"
  14. ---
  15. # Automatically Linked References in Issues, Pull Requests and Commit Messages
  16. When an issue, pull request or comment is posted, the text description is parsed
  17. in search for references. These references will be shown as links in the Issue View
  18. and, in some cases, produce certain _actions_.
  19. Likewise, commit messages are parsed when they are listed, and _actions_
  20. are can be triggered when they are pushed to the main branch.
  21. To prevent the creation of unintended references, there are certain rules
  22. for them to be recognized. For example, they should not be included inside code
  23. text. They should also be reasonably cleared from their surrounding text
  24. (for example, using spaces).
  25. ## User, Team and Organization Mentions
  26. When a text in the form `@username` is found and `username` matches the name
  27. of an existing user, a _mention_ reference is created. This will be shown
  28. by changing the text into a link to said user's profile, and possibly create
  29. a notification for the mentioned user depending on whether they have
  30. the necessary permission to access the contents.
  31. Example:
  32. > [@John](#), can you give this a look?
  33. This is also valid for teams and organizations:
  34. > [@Documenters](#), we need to plan for this.
  35. > [@CoolCompanyInc](#), this issue concerns us all!
  36. Teams will receive mail notifications when appropriate, but whole organizations won't.
  37. Commit messages do not produce user notifications.
  38. ## Commits
  39. Commits can be referenced using their SHA1 hash, or a portion of it of
  40. at least seven characters. They will be shown as a link to the corresponding
  41. commit.
  42. Example:
  43. > This bug was introduced in [e59ff077](#)
  44. ## Issues and Pull Requests
  45. A reference to another issue or pull request can be created using the simple
  46. notation `#1234`, where _1234_ is the number of an issue or pull request
  47. in the same repository. These references will be shown as links to the
  48. referenced content.
  49. The effect of creating this type of reference is that a _notice_ will be
  50. created in the referenced document, provided the creator of the reference
  51. has reading permissions on it.
  52. Example:
  53. > This seems related to [#1234](#)
  54. Issues and pull requests in other repositories can be referred to as well
  55. using the form `owner/repository#1234`:
  56. > This seems related to [mike/compiler#1234](#)
  57. Alternatively, the `!1234` notation can be used as well. Even when in Gitea
  58. a pull request is a form of issue, the `#1234` form will always link to
  59. an issue; if the linked entry happens to be a pull request instead, Gitea
  60. will redirect as appropriate. With the `!1234` notation, a pull request
  61. link will be created, which will be redirected to an issue if required.
  62. However, this distinction could be important if an external tracker is
  63. used, where links to issues and pull requests are not interchangeable.
  64. ## Actionable References in Pull Requests and Commit Messages
  65. Sometimes a commit or pull request may fix or bring back a problem documented
  66. in a particular issue. Gitea supports closing and reopening the referenced
  67. issues by preceding the reference with a particular _keyword_. Common keywords
  68. include "closes", "fixes", "reopens", etc. This list can be
  69. [customized]({{< ref "/doc/advanced/config-cheat-sheet.en-us.md" >}}) by the
  70. site administrator.
  71. Example:
  72. > This PR _closes_ [#1234](#)
  73. If the actionable reference is accepted, this will create a notice on the
  74. referenced issue announcing that it will be closed when the referencing PR
  75. is merged.
  76. For an actionable reference to be accepted, _at least one_ of the following
  77. conditions must be met:
  78. * The commenter has permissions to close or reopen the issue at the moment
  79. of creating the reference.
  80. * The reference is inside a commit message.
  81. * The reference is posted as part of the pull request description.
  82. In the last case, the issue will be closed or reopened only if the merger
  83. of the pull request has permissions to do so.
  84. Additionally, only pull requests and commit messages can create an action,
  85. and only issues can be closed or reopened this way.
  86. The default _keywords_ are:
  87. * **Closing**: close, closes, closed, fix, fixes, fixed, resolve, resolves, resolved
  88. * **Reopening**: reopen, reopens, reopened
  89. ## Time tracking in Pull Requests and Commit Messages
  90. When commit or merging of pull request results in automatic closing of issue
  91. it is possible to also add spent time resolving this issue through commit message.
  92. To specify spent time on resolving issue you need to specify time in format
  93. `@<number><time-unit>` after issue number. In one commit message you can specify
  94. multiple fixed issues and spent time for each of them.
  95. Supported time units (`<time-unit>`):
  96. * `m` - minutes
  97. * `h` - hours
  98. * `d` - days (equals to 8 hours)
  99. * `w` - weeks (equals to 5 days)
  100. * `mo` - months (equals to 4 weeks)
  101. Numbers to specify time (`<number>`) can be also decimal numbers, ex. `@1.5h` would
  102. result in one and half hours. Multiple time units can be combined, ex. `@1h10m` would
  103. mean 1 hour and 10 minutes.
  104. Example of commit message:
  105. > Fixed #123 spent @1h, refs #102, fixes #124 @1.5h
  106. This would result in 1 hour added to issue #123 and 1 and half hours added to issue #124.
  107. ## External Trackers
  108. Gitea supports the use of external issue trackers, and references to issues
  109. hosted externally can be created in pull requests. However, if the external
  110. tracker uses numbers to identify issues, they will be indistinguishable from
  111. the pull requests hosted in Gitea. To address this, Gitea allows the use of
  112. the `!` marker to identify pull requests. For example:
  113. > This is issue [#1234](#), and links to the external tracker.
  114. > This is pull request [!1234](#), and links to a pull request in Gitea.
  115. The `!` and `#` can be used interchangeably for issues and pull request _except_
  116. for this case, where a distinction is required. If the repository uses external
  117. tracker, commit message for squash merge will use `!` as reference by default.
  118. ## Issues and Pull Requests References Summary
  119. This table illustrates the different kinds of cross-reference for issues and pull requests.
  120. In the examples, `User1/Repo1` refers to the repository where the reference is used, while
  121. `UserZ/RepoZ` indicates a different repository.
  122. | Reference in User1/Repo1 | Repo1 issues are external | RepoZ issues are external | Should render |
  123. |---------------------------|:-------------------------:|:-------------------------:|----------------------------------|
  124. | `#1234` | no | N/A | A link to issue/pull 1234 in `User1/Repo1` |
  125. | `!1234` | no | N/A | A link to issue/pull 1234 in `User1/Repo1` |
  126. | `#1234` | yes | N/A | A link to _external issue_ 1234 for `User1/Repo1` |
  127. | `!1234` | yes | N/A | A link to _PR_ 1234 for `User1/Repo1` |
  128. | `User1/Repo1#1234` | no | N/A | A link to issue/pull 1234 in `User1/Repo1` |
  129. | `User1/Repo1!1234` | no | N/A | A link to issue/pull 1234 in `User1/Repo1` |
  130. | `User1/Repo1#1234` | yes | N/A | A link to _external issue_ 1234 for `User1/Repo1` |
  131. | `User1/Repo1!1234` | yes | N/A | A link to _PR_ 1234 for `User1/Repo1` |
  132. | `UserZ/RepoZ#1234` | N/A | no | A link to issue/pull 1234 in `UserZ/RepoZ` |
  133. | `UserZ/RepoZ!1234` | N/A | no | A link to issue/pull 1234 in `UserZ/RepoZ` |
  134. | `UserZ/RepoZ#1234` | N/A | yes | A link to _external issue_ 1234 for `UserZ/RepoZ` |
  135. | `UserZ/RepoZ!1234` | N/A | yes | A link to _PR_ 1234 for `UserZ/RepoZ` |
  136. | **Alphanumeric issue IDs:** | - | - | - |
  137. | `AAA-1234` | yes | N/A | A link to _external issue_ `AAA-1234` for `User1/Repo1` |
  138. | `!1234` | yes | N/A | A link to _PR_ 1234 for `User1/Repo1` |
  139. | `User1/Repo1!1234` | yes | N/A | A link to _PR_ 1234 for `User1/Repo1` |
  140. | _Not supported_ | N/A | yes | A link to _external issue_ `AAA-1234` for `UserZ/RepoZ` |
  141. | `UserZ/RepoZ!1234` | N/A | yes | A link to _PR_ 1234 in `UserZ/RepoZ` |
  142. _The last section is for repositories with external issue trackers that use alphanumeric format._
  143. _**N/A**: not applicable._
  144. Note: automatic references between repositories with different types of issues (external vs. internal) are not fully supported
  145. and may render invalid links.