Fix orb init failing when orb-publishing context already exists#1193
Open
nanophate wants to merge 1 commit intoCircleCI-Public:mainfrom
Open
Fix orb init failing when orb-publishing context already exists#1193nanophate wants to merge 1 commit intoCircleCI-Public:mainfrom
nanophate wants to merge 1 commit intoCircleCI-Public:mainfrom
Conversation
The error string check in initOrb used a hardcoded message that no longer matches what the REST API (or GQL API) returns when a context with the same name already exists. Use a case-insensitive check for "already exists" so the CLI gracefully continues regardless of which API path is used. Fixes CircleCI-Public#1192 Made-with: Cursor
| err = contextAPI.CreateContext("orb-publishing") | ||
| if err != nil { | ||
| if strings.Contains(err.Error(), "A context named orb-publishing already exists") { | ||
| if strings.Contains(strings.ToLower(err.Error()), "already exists") { |
Contributor
There was a problem hiding this comment.
I think you might need another case here in order to match the error returned by the graphql endpoint? The example you provided has an underscore in that string: "Error creating context: ALREADY_EXISTS"
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.
Summary
initOrbthat causescircleci orb initto fail with"Error: A context already exists with this name"when theorb-publishingcontext already exists in the organization (e.g., created by a teammate)."A context named orb-publishing already exists", which doesn't match what the REST API ("A context already exists with this name") or GQL API ("Error creating context: ALREADY_EXISTS") actually returns."already exists"so the CLI gracefully continues regardless of API path.Fixes #1192
Test plan
circleci orb initin an org whereorb-publishingcontext already exists, select "Yes, set up a publishing context with my API key" — should print`orb-publishing` context already exists, continuing onand proceedcircleci orb initin an org with no existingorb-publishingcontext — should create the context normallycircleci orb initand select "No, I'll do this later" — should skip context creation as before