github / github/docs

The gihub.ref description is confusing and incorrect, particularly for PRs

Abierto
#43,055 7 comentarios 0 reacciones 0 asignados Ver en GitHub
content github_actions never-stale
Lenguaje dominante
TypeScript
Estrellas
20.8k
Forks
68.7k
Merge medio
12 h 24 min
PR fusionados (30 d)
105

Descripción

### Code of Conduct

- [x] I have read and agree to the GitHub Docs project's [Code of Conduct](https://github.com/github/docs/blob/main/.github/CODE_OF_CONDUCT.md)

### What article on docs.github.com is affected?

https://docs.github.com/en/actions/reference/workflows-and-actions/contexts#github-context

### What part(s) of the article would you like to see updated?

The description for `github.ref` is confusing, misleading and incorrect, particularly for PR events.

> The fully-formed ref of the branch or tag that triggered the workflow run. For workflows triggered by `push`, this is the branch or tag ref that was pushed. For workflows triggered by `pull_request` that were not merged, this is the pull request merge branch. If the pull request was merged, this is the head branch. For workflows triggered by `release`, this is the release tag created. For other triggers, this is the branch or tag ref that triggered the workflow run. This is only set if a branch or tag is available for the event type. The ref given is fully-formed, meaning that for branches the format is `refs/heads/`. For pull requests events except `pull_request_target` that were not merged, it is `refs/pull//merge`. `pull_request_target` events have the `ref` from the base branch. For tags it is `refs/tags/`. For example, `refs/heads/feature-branch-1`.

Firstly, it's quite hard to follow the different branching logic of that parapgrah. **Can this be formatted better**, e.g. with nested bullet points?

Secondly, particularly for PR events, the logic is quite unclear, and incorrect in some places. The description mentions

> pull requests events

but doesn't define them what these are. Is it the following subset of triggers?

- [`pull_request`](https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#pull_request)
- [`issue_comment`](https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#pull_request_comment-use-issue_comment)
- [`pull_request_review`](https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#pull_request_review)
- [`pull_request_review_comment`](https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#pull_request_review_comment)
- [`pull_request_target`](https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#pull_request_target)

Assuming this is the case, my understanding of the logic is as follows:

1. `pull_request` events with a `closed` activity type that **were merged**: `github.ref` = `refs/heads/`
2. All other `pull_request` events: `github.ref` = `refs/pull//merge`
3. All `pull_request_target` events (potentially excluding merged events): `github.ref` = `refs/heads/`
4. `issue_comment`, `pull_request_review` and `pull_request_review_comment` (and potentially merged `pull_request_target`) events: `github.ref` = `refs/pull//merge`

Problems to highlight:

1. It's unclear whether "pull requests events except `pull_request_target` that were not merged" includes merged `pull_request_target` events. My tests suggest it doesn't; merged `pull_request_target` events show `refs/heads/main`, not `refs/pull//merge`. **What is this line trying to say?**
2. On a merged `pull_request` event, my tests show ``, not ``. **There is a mistake in the description.**
3. For `pull_request_target` events, regardless of PR direction (`main` -> `test` or `test` -> `main`), my tests show `refs/heads/main`. **Is it always the repo default, not the PR base?**
4. My tests show `issue_comment` events use `refs/heads/main` (regardless of PR direction), not `refs/pull//merge`. **Are these events not part of the PR logic? Does it always use the repo default?**
5. If we're being picky, there's a case to be made that "workflows triggered by `pull_request` that were not merged" means "`closed` and not merged" - meaning other activity types might not be included in the list. **This could be worded better**

Is the following summary more accurate?

- All `pull_request_target` events: `refs/heads/`
- Merged `pull_request` events: `refs/heads/`
- All other `pull_request` events, and all `pull_request_review` and `pull_request_review_comment` events: `refs/pull//merge`
- `issue_comment` events: `refs/heads/`

### Additional information

_No response_

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.