Skip to content

refactor: migrate resource_github_issue_label to context-aware CRUD a…#3342

Open
slymanmrcan wants to merge 2 commits into
integrations:mainfrom
slymanmrcan:refactor/migrate-resource-github-issue-label-to-tflog-and-context
Open

refactor: migrate resource_github_issue_label to context-aware CRUD a…#3342
slymanmrcan wants to merge 2 commits into
integrations:mainfrom
slymanmrcan:refactor/migrate-resource-github-issue-label-to-tflog-and-context

Conversation

@slymanmrcan

@slymanmrcan slymanmrcan commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

Addresses parts of #3070
Addresses parts of #2996


Before the change?

  • resource_github_issue_label uses legacy Create/Read/Update/Delete
    schema functions and log.Printf for logging.

After the change?

  • Migrated to CreateContext/ReadContext/UpdateContext/DeleteContext
  • Function signatures updated to (ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics
  • Replaced log.Printf with tflog.Info for structured logging
  • Removed manual context.Background() calls
  • Wrapped error returns with diag.FromErr()

Pull request checklist

  • Schema migrations have been created if needed — N/A, no schema change
  • Tests for the changes have been added — N/A, no behavior change
  • Docs have been reviewed and added / updated if needed — N/A

Does this introduce a breaking change?

  • No

@github-actions

Copy link
Copy Markdown

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@deiga

deiga commented Apr 18, 2026

Copy link
Copy Markdown
Collaborator

Please remove the resolves comment, since it adresses the issue only partly. And "resolves" will close the issue

deiga
deiga previously approved these changes Apr 18, 2026

@deiga deiga left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM!

Thanks for the contribution!

@deiga deiga added this to the v6.13.0 Release milestone Apr 18, 2026
@deiga deiga added the Type: Maintenance Any dependency, housekeeping, and clean up Issue or PR label Apr 18, 2026
@slymanmrcan

Copy link
Copy Markdown
Contributor Author

I just removed it from the description

@deiga

deiga commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Would you be available to rebase this (possibly multiple times) during the next week? We're going to release 6.13.0 and will try to land some of these open PRs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors resource_github_issue_label to use Terraform Plugin SDK v2 context-aware CRUD function signatures and structured logging via tflog, aligning the resource with ongoing provider-wide migrations tracked in #2996 and #3070.

Changes:

  • Migrated the resource from legacy Create/Read/Update/Delete to CreateContext/ReadContext/UpdateContext/DeleteContext.
  • Updated CRUD implementations to return diag.Diagnostics and wrap errors with diag.FromErr.
  • Replaced log.Printf usage with tflog.Info structured logging and removed context.Background() usage.

Comment thread github/resource_github_issue_label.go Outdated
Comment thread github/resource_github_issue_label.go Outdated
@slymanmrcan

Copy link
Copy Markdown
Contributor Author

Yes, I can rebase it during the next week as needed.

I’ll rebase now and address the Copilot review comments as well.

@slymanmrcan slymanmrcan force-pushed the refactor/migrate-resource-github-issue-label-to-tflog-and-context branch from 241dc85 to 40c2608 Compare June 5, 2026 04:45
deiga
deiga previously approved these changes Jun 5, 2026

@deiga deiga left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@stevehipwell even though there are other parts here that could be refactored, I would suggest we do the minimum here to get this merged.

@deiga deiga requested a review from stevehipwell June 5, 2026 17:31

@stevehipwell stevehipwell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

For me the bare minimum here would be to separate create & update and remove the call to read from them.

@slymanmrcan slymanmrcan force-pushed the refactor/migrate-resource-github-issue-label-to-tflog-and-context branch from ba9fec5 to 9c162ad Compare June 11, 2026 10:55
@slymanmrcan

Copy link
Copy Markdown
Contributor Author

Thanks, I separated the create and update handlers and removed the explicit read call from both paths while keeping the existing idempotent create behavior for default GitHub labels.

Comment thread github/resource_github_issue_label.go Outdated
Comment thread github/resource_github_issue_label.go Outdated
Comment thread github/resource_github_issue_label.go Outdated
Comment thread github/resource_github_issue_label.go Outdated
Comment thread github/resource_github_issue_label.go Outdated
Comment thread github/resource_github_issue_label.go Outdated
@slymanmrcan slymanmrcan force-pushed the refactor/migrate-resource-github-issue-label-to-tflog-and-context branch from 9c162ad to ad3d0c9 Compare June 11, 2026 12:16
Comment thread github/resource_github_issue_label.go
Comment thread github/resource_github_issue_label.go Outdated
Comment thread github/resource_github_issue_label.go Outdated
Comment thread github/resource_github_issue_label.go Outdated
Comment thread github/resource_github_issue_label.go Outdated
Comment thread github/resource_github_issue_label.go Outdated
Comment thread github/resource_github_issue_label.go
Comment thread github/resource_github_issue_label.go Outdated
@slymanmrcan slymanmrcan force-pushed the refactor/migrate-resource-github-issue-label-to-tflog-and-context branch from ad3d0c9 to 43498d3 Compare June 13, 2026 13:43

@stevehipwell stevehipwell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@slymanmrcan this is looking good. There are still a couple of outstanding comments to address and it looks like you haven't run the strict linting for new code?

@slymanmrcan slymanmrcan force-pushed the refactor/migrate-resource-github-issue-label-to-tflog-and-context branch 4 times, most recently from 88958c6 to 3fef38e Compare June 15, 2026 23:47
@slymanmrcan

Copy link
Copy Markdown
Contributor Author

Thanks, my mistake. I missed the strict new-code lint locally.
I’ve run it now and addressed the findings in the latest push.

@stevehipwell stevehipwell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for making the changes, I've added some feedback so you can follow the idiomatic patterns.

Comment thread github/resource_github_issue_label.go Outdated
Comment thread github/resource_github_issue_label.go Outdated
Comment thread github/resource_github_issue_label.go Outdated
Comment thread github/resource_github_issue_label.go Outdated
Comment thread github/resource_github_issue_label.go Outdated
@slymanmrcan slymanmrcan force-pushed the refactor/migrate-resource-github-issue-label-to-tflog-and-context branch 2 times, most recently from 88e2360 to c20bfef Compare June 17, 2026 21:26
@stevehipwell

Copy link
Copy Markdown
Collaborator

Thanks @slymanmrcan, this looks good. Could you please rebase and let us know if you've run the acceptance tests for the resource locally?

stevehipwell
stevehipwell previously approved these changes Jun 18, 2026

@stevehipwell stevehipwell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

deiga
deiga previously approved these changes Jun 18, 2026

@robert-crandall robert-crandall left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for taking this on - moving to context-aware CRUD and tflog is a nice cleanup, and I appreciate the careful function split. Both questions I left feel like behavior changes worth a second look. Happy to help think through it!

Comment thread github/resource_github_issue_label.go
Comment thread github/resource_github_issue_label.go Outdated
orgName, repoName, originalName)
if err != nil && resp.StatusCode != http.StatusNotFound {
return err
githubLabel, resp, err := client.Issues.CreateLabel(ctx, orgName, repoName, label)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Quick question on intent: the old combined function did a GetLabel first and called EditLabel if the label already existed (the removed comment explained it - new repos ship default labels, and a name clash returns 422). This version calls CreateLabel directly, so a pre-existing label would now 422 instead of being adopted. That may well be the better Terraform behavior (import instead of adopt) - just flagging since the checklist says "no behavior change." Totally fine if intentional.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this should be Terraform based logic, so fail if the label already exists. We have github_issue_labels to act as an authoritative source.

@slymanmrcan slymanmrcan dismissed stale reviews from deiga and stevehipwell via 9da13ec June 19, 2026 10:28
@slymanmrcan slymanmrcan force-pushed the refactor/migrate-resource-github-issue-label-to-tflog-and-context branch from c20bfef to 9da13ec Compare June 19, 2026 10:28
@slymanmrcan

Copy link
Copy Markdown
Contributor Author

Thanks for the review! I’ve pushed the fixes now: color/description are set from Read again, and Create preserves the previous GetLabel-then-EditLabel behavior for existing labels.

Comment thread github/resource_github_issue_label.go Outdated
repoName := d.Get("repository").(string)
name := d.Get("name").(string)
color := d.Get("color").(string)
// resourceGithubIssueLabelCreate creates an issue label.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's not keep comments around if they don't explain something non-obvious

Suggested change
// resourceGithubIssueLabelCreate creates an issue label.

Comment thread github/resource_github_issue_label.go Outdated
func resourceGithubIssueLabelImport(_ context.Context, d *schema.ResourceData, _ any) ([]*schema.ResourceData, error) {
repoName, name, err := parseID2(d.Id())
if err != nil {
return nil, err

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

To make the DX nicer, lets add a helpful error message here :)

Suggested change
return nil, err
return nil, fmt.Errorf("Import failed due to ID format mismatch in %s. Please ensure import ID follows the pattern `<repository name>:<label name>.", d.Id())

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

Labels

Type: Maintenance Any dependency, housekeeping, and clean up Issue or PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants