fix: restore adopt-existing behavior in github_issue_label create (regression in v6.13.0)#3560
Open
aklinkert wants to merge 1 commit into
Open
fix: restore adopt-existing behavior in github_issue_label create (regression in v6.13.0)#3560aklinkert wants to merge 1 commit into
aklinkert wants to merge 1 commit into
Conversation
Since PR integrations#3342 (v6.13.0) split the idempotent create-or-update into separate Create and Update funcs, resourceGithubIssueLabelCreate calls Issues.CreateLabel directly with no GET-first existence check. Creating a label whose name already exists on the repository now fails with "422 Validation Failed [already_exists]". This regressed a documented behavior and breaks the common case of managing GitHub's default seeded labels (bug, documentation, enhancement, ...) on a new repository. Restore the pre-6.13.0 behavior in the context-aware Create path: GET the label first and, if it already exists, EditLabel (adopt) it instead of CreateLabel; a 404 falls through to CreateLabel as before. Fixes integrations#3559 Signed-off-by: Alex Klinkert <alex.klinkert@cloudpilots.com>
|
👋 Hi, and thank you for this contribution! This repo is maintained by GitHub and community members on a best-effort basis. We'll get to this as soon as we can. You can help us prioritize by joining the discussion on open issues and PRs, sharing details on the changes you need, and reviewing other contributions. 🤖 This is an automated message. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #3559
Before the change?
resource "github_issue_label"used to be idempotent on create: a singleresourceGithubIssueLabelCreateOrUpdatedid a GET first and adopted (updated)a label that already existed instead of creating it. PR #3342 (released in
v6.13.0) split that into context-aware
CreateandUpdatefunctions, and thenew
Createcallsclient.Issues.CreateLabel(...)directly with no GET-firstexistence check.
As a result, creating a label whose name already exists on the repository fails
the very first apply with
422 Validation Failed [already_exists]. This is acommon case, not an edge case: GitHub (and GHES) seed every new repository with
default labels (
bug,documentation,duplicate,enhancement,good first issue,help wanted,invalid,question,wontfix), so anyconfig that manages one of those names now breaks on first apply. The resource's
own docs still promise the "check if the label exists, then update, otherwise
create" behavior.
After the change?
resourceGithubIssueLabelCreatenow restores the pre-6.13.0 adopt-existingbehavior, in the current context-aware CRUD style: it calls
client.Issues.GetLabel(ctx, owner, repo, name)first; if the label alreadyexists it issues an
EditLabel(adopting/updating it), and if the GET returns404it falls through toCreateLabelexactly as today. Any non-404 error fromthe GET is returned.
diag.Diagnostics/contextsignatures andtflogloggingare kept consistent with the rest of the file.
An acceptance test (
adopts a pre-existing label on create without error) isadded: it manages the default
buglabel on anauto_initrepository andasserts the apply succeeds and the label's color/description are updated.
Pull request checklist
Does this introduce a breaking change?
Please see our docs on breaking changes to help!