Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct documentation of provider configuration, and deprecate organization argument #735

Merged
merged 4 commits into from
Apr 9, 2021

Conversation

tibbes
Copy link
Contributor

@tibbes tibbes commented Mar 19, 2021

While investigating #662, I found that the code handling the owner and organization arguments to the GitHub provider could be simplified, and also that the documentation was incorrect.

Although the docs say that owner is for user ids (like torvalds) and organization is for organization ids (like github), in fact, either type of value can be put in either argument.

Given this, I suggest that we deprecate organization, and just use owner.

The main change in this pull request is to make organization and GITHUB_ORGANIZATION deprecated. Making arguments deprecated should only me done as part of a minor (or higher) release, according to the Hashicorp versioning guidelines.

In addition, the documentation says that owner can be set via the environment variable GITHUB_OWNER, and organization can be set via the environment variable GITHUB_ORGANIZATION. However, in reality, both environment variables (with GITHUB_ORGANIZATION taking priority) were used as the default value of both owner and organization. This had the odd side-effect of making the precedence of these methods inconsistent. From high to low precedence, the order is:

  • setting organization in the provider configuration
  • setting the GITHUB_ORGANIZATION environment variable
  • setting the GITHUB_OWNER environment variable
  • setting owner in the provider configuration

That is, organization overrides GITHUB_ORGANIZATION (as I'd expect), but GITHUB_OWNER overrides owner (that seems backwards).

Changing this behaviour seems desirable, but as it would be a backwards incompatible change, the Hashicorp versioning guidelines suggest we should only do so as part of a major release. Therefore, I have not changed the configuration precedence in this pull request, but I have put a warning in the documentation saying we might do so in future.

- Remove 'Organization' field, which was never read
- Remove 'Individual' field, which was never read
- Replace 'Anonymous' field with a function (as the field is derived
  from the value of 'Token')
We don't need `organization` and `GITHUB_ORGANIZTION`, because the
current behaviour is that the user can put a user name _or_ an
organization name in any of `owner`, `organization`, `GITHUB_OWNER`, or
`GITHUB_ORGANIZATION`.

It therefore seems clearer to just keep `owner` and `GITHUB_OWNER`.

Unfortunately, the current precedence of owner, GITHUB_OWNER,
organization, GITHUB_ORGANIZATION is also a bit confusing. From high
precedence to low precedence, the order is:

- organization
- GITHUB_ORGANIZATION
- GITHUB_OWNER
- owner

For backwards compatibility, in minor/patch releases we need to preserve
this order. However, I've contained the code that does this in a single
clearly marked block of code in providerConfigure so that it can be
removed easily in a future major release.

I've updated the documentation with:

- a description of the current behaviour
- the fact that organization and GITHUB_ORGANIZATION are deprecated
- a warning that the precedence of owners/GITHUB_OWNER may change
Copy link
Contributor

@majormoses majormoses left a comment

Choose a reason for hiding this comment

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

Not much of a go developer, LGTM. It's a good solution to a bad problem, I would ideally like to see this release go out and then decide when we are willing to force the breaking change. I honestly don't see a big reason to wait long, if we have breaking changes that affect a small area it's much easier to review changelogs and upgrade then it is with large releases with multiple breaking changes.

@jcudit jcudit added this to the v4.7.0 milestone Apr 6, 2021
Copy link
Contributor

@jcudit jcudit left a comment

Choose a reason for hiding this comment

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

I think this is a necessary change to get into the project to clean up from past mistakes. A huge thank you @tibbes for such a readable fix. I feel this will remove more frustration than it causes, so lets ship and track the removal of the backwards compatibility for the next major release in the coming months.

Changes to this part of the code base have historically not gone smoothly, so I'll be keeping an eye out for related bugs after this is released. Thanks to anyone who can quickly point out fixes as we upgrade this area. 🚀

@jcudit jcudit modified the milestones: v4.7.0, v4.8.0, v4.9.0 Apr 9, 2021
@jcudit jcudit merged commit bff31eb into integrations:master Apr 9, 2021
@jcudit jcudit mentioned this pull request Jun 3, 2021
kfcampbell pushed a commit to kfcampbell/terraform-provider-github that referenced this pull request Jul 26, 2022
…zation argument (integrations#735)

* Remove dead function

* Remove redundant call to os.Getenv

* Simplify github.Config struct

- Remove 'Organization' field, which was never read
- Remove 'Individual' field, which was never read
- Replace 'Anonymous' field with a function (as the field is derived
  from the value of 'Token')

* Deprecate organization and GITHUB_ORGANIZATION

We don't need `organization` and `GITHUB_ORGANIZTION`, because the
current behaviour is that the user can put a user name _or_ an
organization name in any of `owner`, `organization`, `GITHUB_OWNER`, or
`GITHUB_ORGANIZATION`.

It therefore seems clearer to just keep `owner` and `GITHUB_OWNER`.

Unfortunately, the current precedence of owner, GITHUB_OWNER,
organization, GITHUB_ORGANIZATION is also a bit confusing. From high
precedence to low precedence, the order is:

- organization
- GITHUB_ORGANIZATION
- GITHUB_OWNER
- owner

For backwards compatibility, in minor/patch releases we need to preserve
this order. However, I've contained the code that does this in a single
clearly marked block of code in providerConfigure so that it can be
removed easily in a future major release.

I've updated the documentation with:

- a description of the current behaviour
- the fact that organization and GITHUB_ORGANIZATION are deprecated
- a warning that the precedence of owners/GITHUB_OWNER may change
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.

3 participants