Skip to content

[clean-repository-handling] Clean repository handling#27

Merged
jgerigmeyer merged 21 commits intomasterfrom
clean-repository-handling
Oct 29, 2019
Merged

[clean-repository-handling] Clean repository handling#27
jgerigmeyer merged 21 commits intomasterfrom
clean-repository-handling

Conversation

@wlonk
Copy link
Copy Markdown

@wlonk wlonk commented Oct 9, 2019

@wlonk wlonk changed the title Clean repository handling [clean-repository-handling] Clean repository handling Oct 9, 2019
@wlonk
Copy link
Copy Markdown
Author

wlonk commented Oct 14, 2019

@davisagli on the old PR, you mentioned:

@wlonk @jgerigmeyer for some other projects we've used the github api to look up github's integer id for the repo. that will be consistent even if the repo gets renamed or transferred to a different owner.
I think that's a good approach, and will implement it here.

@wlonk
Copy link
Copy Markdown
Author

wlonk commented Oct 14, 2019

@davisagli ready for you to look at that change if you want.

@jgerigmeyer jgerigmeyer self-requested a review October 14, 2019 21:14
Copy link
Copy Markdown
Member

@jgerigmeyer jgerigmeyer left a comment

Choose a reason for hiding this comment

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

@wlonk Part of the purpose of this is to use IDs as the unique identifier when comparing repos. So I would expect it to be used in e.g. get_all_org_repos and the RepositoryViewSet.get_queryset view?

@jgerigmeyer
Copy link
Copy Markdown
Member

Copy link
Copy Markdown
Member

@jgerigmeyer jgerigmeyer left a comment

Choose a reason for hiding this comment

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

@wlonk I have a number of ideas for cleanup here. At a high level view, I still think we only need admins to enter owner and name explicitly in the admin, then we use that to get the ID and only use the ID from there on out. I don't see a compelling reason to use (or store) the repo_url at all, since we're really only using it to parse out owner and name.

If you don't mind, I'd like to make a commit with my proposed cleanup here.

@jgerigmeyer
Copy link
Copy Markdown
Member

@wlonk Okay, I'm sure there's some ugly code/architecture in my latest commit, but I'd be happy to talk through it with you and let you do whatever cleanup (or reverting) you like.

* master:
  Fix up tests to use current changes format
  Fix tests
  📦 🛢  Various cleanup:
@jgerigmeyer jgerigmeyer self-requested a review October 15, 2019 21:26
and get it from the model if present, or query the GitHub API as
a fallback, assuming that the current user can access the
current repo via the repo URL.
"""
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't love this deferring, but understand why it might be preferred. I wonder about (also?) trying to populate repo_id on every save?

User, on_delete=models.CASCADE, related_name="repositories"
)
repo_id = models.IntegerField(unique=True)
repo_url = models.URLField()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The only reasons to store this IMO are 1) it's trivial, and 2) for ease of DB sleuthing and admin browsing.

)

def get_repo_url(self, obj) -> Optional[str]:
return f"https://github.com/{obj.repo_owner}/{obj.repo_name}"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't love this. We could store it on the model and populate it lazily (like we're doing for repo_id).

repo_name = repo.repo_name
branch = obj.branch_name
if repo_owner and repo_name and branch:
return f"https://github.com/{repo_owner}/{repo_name}/tree/{branch}"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I also don't love these two hard-coded URLs, but it's not a big deal.

try:
repo.get_repo_id(self.request.user)
except ResponseError:
pass
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So I'd guess this is probably frowned upon? It forces an external API call in-band for any repos which don't have IDs yet -- on every get_queryset... 😬

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yeah, that's a little upsetting. Let's… see if it is a problem maybe?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should only happen once ever per repo in the DB. So I would think in practice it won't be an issue? But let's discuss.

Copy link
Copy Markdown
Author

@wlonk wlonk left a comment

Choose a reason for hiding this comment

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

Generally 👍 on your changes, though I left a few comments to discuss. Detailed discussion tomorrow?

try:
repo.get_repo_id(self.request.user)
except ResponseError:
pass
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yeah, that's a little upsetting. Let's… see if it is a problem maybe?

@wlonk wlonk requested a review from jgerigmeyer October 23, 2019 19:21
* master:
  Stick with 2 seconds.
  Copy semaphore logic from MetaDeploy.
  Use single Redis call to set expiry
  Rewrap some comments
  🛢 Lint python.
  📦 🧶 Combined dep upgrades.
  Bump pytest-django from 3.5.1 to 3.6.0
  Add expire to semaphore
  🛢 Delete new org from SF if initial flow run fails.
  Create orgs from latest task branch, not default repo branch.
@jgerigmeyer
Copy link
Copy Markdown
Member

@wlonk @davisagli I'm satisfied with this PR, and did functional testing. As far as I'm concerned it's ready for review/merge.

Copy link
Copy Markdown
Author

@wlonk wlonk left a comment

Choose a reason for hiding this comment

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

I can't formally approve, as I opened the PR, but I do approve. 💚

@jgerigmeyer jgerigmeyer merged commit 7ddb697 into master Oct 29, 2019
@jgerigmeyer jgerigmeyer deleted the clean-repository-handling branch October 29, 2019 17:50
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