Skip to content

ci: add a workflow for issue and PR validation - #1061

Open
Joaolpridolficarvalho wants to merge 8 commits into
scanapi:mainfrom
Joaolpridolficarvalho:1060
Open

ci: add a workflow for issue and PR validation#1061
Joaolpridolficarvalho wants to merge 8 commits into
scanapi:mainfrom
Joaolpridolficarvalho:1060

Conversation

@Joaolpridolficarvalho

@Joaolpridolficarvalho Joaolpridolficarvalho commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Description

This PR adds a workflow for issue and PR validation. It covers the following scenarios:

  • triggers: on pull request events (opened, edited, reopened, synchronize)
  1. PR doesn't close any issue:
  • Label "Needs-assignment" is added.
  • Comment:

    🇧🇷 Português
    Esta PR não está vinculada a uma issue. Por favor, vincule a issue que esta PR pretende resolver antes de continuar. Siga o Guia do Contribuidor para aprender como vincular uma issue à sua PR. As PRs devem estar associadas a uma issue antes do início da implementação.

    🇬🇧 English
    This PR is not linked to an issue. Please link the issue this PR is intended to resolve before continuing. Please follow the Contributor Guide to learn how to link an issue to your PR. PRs should be associated with an issue before implementation starts.

  • Merge is blocked until the PR is linked to an issue.
  1. PR closes an issue that isn't assigned to anyone:
  • Label "Needs-assignment" is added.
  • Comment:

    🇧🇷 Português
    Esta issue está atualmente atribuída a outra pessoa. Por favor, coordene com o responsável antes de abrir uma PR para esta issue. Se você pretende trabalhar nela, certifique-se de que a issue esteja atribuída a você primeiro. Veja o Guia do Contribuidor para mais informações.

    🇬🇧 English
    This issue is currently assigned to someone else. Please coordinate with the assignee before opening a PR for this issue. If you intend to work on it, please make sure the issue is assigned to you first. See the Contributor Guide for more information.

  • Merge is blocked until the issue is assigned to the PR author.
  1. PR closes an issue that is assigned to someone else:
  • Label "Needs-assignment" is added.
  • Comment:

🇧🇷 Português
Esta issue ainda não está atribuída a ninguém. Por favor, atribua a issue a você antes de abrir uma PR. Siga o Guia do Contribuidor para aprender como reivindicar uma issue. Isso ajuda a evitar que várias pessoas trabalhem na mesma issue ao mesmo tempo.

🇬🇧 English
This issue is not assigned to anyone yet. Please assign the issue to yourself before opening a PR. Please follow the Contributor Guide to learn how to claim an issue. This helps us avoid multiple people working on the same issue at the same time.

  • Merge is blocked until the issue is assigned to the PR author.

Motivation behind this PR?

#1060

What type of change is this?

CI

AI Assistance Disclosure (REQUIRED)

  • No AI tools were used in preparing this PR.
  • If AI tools were used, I have disclosed which ones, and fully reviewed and verified their output.

Checklist

  • A changelog entry was added, or this PR does not require one. Instructions
  • Unit tests were added or updated as needed, or not required for this change. Instructions
  • All unit tests pass locally. Instructions
  • Docstrings or comments were added or updated as needed, or no documentation changes were required. Instructions
  • This PR does not significantly reduce code or docstring coverage.
  • Code follows the project’s style guidelines.
  • ScanAPI was run locally and the changes were manually verified, or this was not necessary. Instructions

Issue

Closes #1060

@Joaolpridolficarvalho
Joaolpridolficarvalho requested review from a team as code owners August 14, 2026 13:08
Comment thread .github/workflows/verify-assign-and-link.yml Fixed

@camilamaia camilamaia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting this workflow together! The overall idea looks good, and I think this will be really helpful to enforce the contributor workflow around issue assignment and PRs.

I have a few suggestions to make the workflow more robust and easier to maintain:

Required changes

  • Use the repository's label naming convention

    • Replace needs-issue with Needs Issue.
    • Replace needs-assignment with Needs Assignment.

    This follows the label naming pattern already used in the repository. Please make sure the exact capitalization is used consistently throughout the workflow.

  • Create the labels before enabling the workflow

    The Needs Issue and Needs Assignment labels need to exist in the repository before this workflow runs. Otherwise, the gh pr edit --add-label / gh issue edit --add-label commands can fail and cause the workflow to break.

  • Remove the warning comments once the problem is resolved

    If a PR initially has no linked issue, the workflow adds a comment asking the contributor to link one. Once the PR is updated and an issue is correctly linked, that comment should be removed.

    The same applies to the assignment check: if the workflow previously reported that the issue was unassigned or assigned to someone else, the corresponding comment should be removed once the issue is correctly assigned to the PR author.

    I'd recommend using a sticky comment with a stable header for this rather than searching for the comment text. The validate-pr-title-v1.yml workflow is a good reference for this approach.

  • Trigger the workflow when the issue assignment changes

    At the moment, the workflow is triggered only by PR events. However, assigning or reassigning an issue is an issue event.

    For example, if a contributor opens a PR while the issue is unassigned and then assigns the issue to themselves, the workflow won't run again. We should add the appropriate issues event so that changes to the assignment trigger the validation.

    This should work in both directions: assigning the issue to the PR author should clear the Needs Assignment state, while reassigning it to someone else should add it again.

Suggestions for robustness and maintainability

  • Use GitHub's linked-issue information instead of parsing the PR body manually.

    gh pr view already exposes the closingIssuesReferences field, so we can use that to retrieve the issue linked to the PR instead of maintaining our own regex for close, fix, resolve, etc. This makes the validation simpler and avoids duplicating GitHub's issue-linking logic.

    For example:

    ISSUE_NUMBER=$(gh pr view "$PR_NUMBER" \
      --json closingIssuesReferences \
      --jq '.closingIssuesReferences[0].number // empty')
  • Consider checking all assignees instead of only the first one.

    GitHub issues can have multiple assignees, so using .assignees[0] may incorrectly report the issue as not assigned to the PR author when the author is assigned but is not the first assignee.

  • Handle changes to the linked issue.

    If a PR is initially linked to issue A and later updated to link to issue B, we should make sure labels and comments associated with issue A are cleaned up. Otherwise, the old issue could be left with a stale Needs Assignment label or warning comment.

  • Consider simplifying the workflow structure.

    I think it would be useful to structure the workflow around the two validations, with each validation following the same pattern:

    1. Get the current state — identify the linked issue and retrieve the information needed for the validation.
    2. Validate the state — determine whether the PR currently satisfies the requirement.
    3. If the validation fails — add the appropriate label and create/update the corresponding sticky comment.
    4. If the validation succeeds — remove the label and remove the corresponding sticky comment.

    This makes the workflow behave in a self-healing way: every time it runs, it brings the PR/issue state back to the state that matches the current validation result.

    It would also be good to avoid duplicating the same label/comment logic for the different failure cases. For example, the "unassigned" and "assigned to someone else" cases can share the same state-management logic while only changing the message.

    More generally, I strongly recommend using the cumbucadev/shared-workflows repository as the main reference when structuring this workflow. The workflows there follow the patterns and conventions we want to use: they are generally clear, clean, and organized, with the validation logic and error handling kept easy to follow.

    Since the intention is to eventually move this workflow into shared-workflows as well, following the existing patterns and best practices there from the beginning will make the transition much easier and keep the workflows consistent across the repository.

Overall, I think the workflow is going in a good direction. Most of these changes are about making the validation state self-healing and keeping the implementation consistent with the patterns we already use in shared-workflows.

@Joaolpridolficarvalho

Joaolpridolficarvalho commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for putting this workflow together! The overall idea looks good, and I think this will be really helpful to enforce the contributor workflow around issue assignment and PRs.

I have a few suggestions to make the workflow more robust and easier to maintain:

Required changes

  • Use the repository's label naming convention

    • Replace needs-issue with Needs Issue.
    • Replace needs-assignment with Needs Assignment.

    This follows the label naming pattern already used in the repository. Please make sure the exact capitalization is used consistently throughout the workflow.

  • Create the labels before enabling the workflow
    The Needs Issue and Needs Assignment labels need to exist in the repository before this workflow runs. Otherwise, the gh pr edit --add-label / gh issue edit --add-label commands can fail and cause the workflow to break.

  • Remove the warning comments once the problem is resolved
    If a PR initially has no linked issue, the workflow adds a comment asking the contributor to link one. Once the PR is updated and an issue is correctly linked, that comment should be removed.
    The same applies to the assignment check: if the workflow previously reported that the issue was unassigned or assigned to someone else, the corresponding comment should be removed once the issue is correctly assigned to the PR author.
    I'd recommend using a sticky comment with a stable header for this rather than searching for the comment text. The validate-pr-title-v1.yml workflow is a good reference for this approach.

  • Trigger the workflow when the issue assignment changes
    At the moment, the workflow is triggered only by PR events. However, assigning or reassigning an issue is an issue event.
    For example, if a contributor opens a PR while the issue is unassigned and then assigns the issue to themselves, the workflow won't run again. We should add the appropriate issues event so that changes to the assignment trigger the validation.
    This should work in both directions: assigning the issue to the PR author should clear the Needs Assignment state, while reassigning it to someone else should add it again.

Suggestions for robustness and maintainability

  • Use GitHub's linked-issue information instead of parsing the PR body manually.
    gh pr view already exposes the closingIssuesReferences field, so we can use that to retrieve the issue linked to the PR instead of maintaining our own regex for close, fix, resolve, etc. This makes the validation simpler and avoids duplicating GitHub's issue-linking logic.
    For example:

    ISSUE_NUMBER=$(gh pr view "$PR_NUMBER" \
      --json closingIssuesReferences \
      --jq '.closingIssuesReferences[0].number // empty')
  • Consider checking all assignees instead of only the first one.
    GitHub issues can have multiple assignees, so using .assignees[0] may incorrectly report the issue as not assigned to the PR author when the author is assigned but is not the first assignee.

  • Handle changes to the linked issue.
    If a PR is initially linked to issue A and later updated to link to issue B, we should make sure labels and comments associated with issue A are cleaned up. Otherwise, the old issue could be left with a stale Needs Assignment label or warning comment.

  • Consider simplifying the workflow structure.
    I think it would be useful to structure the workflow around the two validations, with each validation following the same pattern:

    1. Get the current state — identify the linked issue and retrieve the information needed for the validation.
    2. Validate the state — determine whether the PR currently satisfies the requirement.
    3. If the validation fails — add the appropriate label and create/update the corresponding sticky comment.
    4. If the validation succeeds — remove the label and remove the corresponding sticky comment.

    This makes the workflow behave in a self-healing way: every time it runs, it brings the PR/issue state back to the state that matches the current validation result.
    It would also be good to avoid duplicating the same label/comment logic for the different failure cases. For example, the "unassigned" and "assigned to someone else" cases can share the same state-management logic while only changing the message.
    More generally, I strongly recommend using the cumbucadev/shared-workflows repository as the main reference when structuring this workflow. The workflows there follow the patterns and conventions we want to use: they are generally clear, clean, and organized, with the validation logic and error handling kept easy to follow.
    Since the intention is to eventually move this workflow into shared-workflows as well, following the existing patterns and best practices there from the beginning will make the transition much easier and keep the workflows consistent across the repository.

Overall, I think the workflow is going in a good direction. Most of these changes are about making the validation state self-healing and keeping the implementation consistent with the patterns we already use in shared-workflows.

@camilamaia @niltonpimentel02 I'm having a problem revalidating the pull request after assigning the author. For some reason, the workflow doesn't run, just like when I set the issue events as triggers.
At the moment, I've tested at https://github.com/[Joaolpridolficarvalho/teste](https://github.com/Joaolpridolficarvalho/teste). But it's so dirty. I'll clean it.

@camilamaia

Copy link
Copy Markdown
Member

@Joaolpridolficarvalho the link returns 404 for me

@Joaolpridolficarvalho

Joaolpridolficarvalho commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

@Joaolpridolficarvalho the link returns 404 for me

This should work.
https://github.com/Joaolpridolficarvalho/teste

@Joaolpridolficarvalho
Joaolpridolficarvalho marked this pull request as ready for review September 10, 2026 13:23
@Joaolpridolficarvalho

Copy link
Copy Markdown
Contributor Author

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ci: add PR validation for issue assignment

3 participants