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

The or_create for new GH teams does not create new teams #1025

Open
MrMarvin opened this issue Feb 21, 2020 · 5 comments
Open

The or_create for new GH teams does not create new teams #1025

MrMarvin opened this issue Feb 21, 2020 · 5 comments

Comments

@MrMarvin
Copy link
Contributor

Context

Given we have a Shipit instance that formerly only members of our orgs Github team admin had access to. We now added the handle myorg/developers to the github.oauth.teams config list.

Issue

All requests to Shipit now fail due to an exception raised:

NoMethodError (undefined method `each' for nil:NilClass)

Analysis

irb(main):005:0> team = Shipit::Team.find_or_create_by_handle('myorg/developers')
Traceback (most recent call last):
        1: from (irb):5
NoMethodError (undefined method `each' for nil:NilClass)


irb(main):006:0> team = Shipit::Team.find_or_create_by_handle('myorg/admins')
=> #<Shipit::Team id: 4, github_id: 54321, api_url: "https://api.github.com/organizations/12345/team/...", slug: "admins", name: "admins", organization: "myorg", created_at: "2020-02-21 09:35:32", updated_at: "2020-02-21 09:35:32">

Please note: The first case also seem to not reach out got Github, at least it returns instantly, too fast for a networked API call.

Workaround

Manually invoke

Shipit::Team.fetch_and_create_from_github('myorg','developers')

via rails console

@casperisfine
Copy link
Contributor

It's documented in the setup guide:

github.oauth.teams optional, required only if you want to restrict access to a set of GitHub teams.

If it's missing, the Shipit installation will be public unless you setup another authentication method.

After you change the list of teams, you have to invoke bin/rake teams:fetch to prefetch the team members.

**`github.oauth.teams`** optional, required only if you want to restrict access to a set of GitHub teams.

Maybe we could fetch the missing team on the fly though, not sure.

@casperisfine
Copy link
Contributor

Also it certainly shouldn't fail with a NoMethodError on nil.

@MrMarvin
Copy link
Contributor Author

The mentioned rake task ultimate invokes #find_or_create_by_handle, which then fails with the NoMethodError.

@MrMarvin
Copy link
Contributor Author

MrMarvin commented Feb 21, 2020

After looking into the stacktrace for a little longer, it seems to be an issue in a different area: Caching.
It appears Shipit-engine has cached an empty response from Github (for whatever reason it was empty to begin with...) in the github api faraday cache:

irb(main):005:0> Shipit.github.api.org_teams('myorg', per_page: 100)
=> nil

irb(main):023:0> Rails.cache.clear
=> "OK"

irb(main):024:0> Shipit.github.api.org_teams('myorg', per_page: 100)
=> [{:name=>"some-team",
[...]

@casperisfine
Copy link
Contributor

That's interesting. I'd need to investigate wether that comes from HTTP caching or from an application layer of cache.

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

No branches or pull requests

2 participants