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

Add Support for Storing Repo Labels #1683

Merged
merged 1 commit into from
Oct 5, 2022
Merged

Add Support for Storing Repo Labels #1683

merged 1 commit into from
Oct 5, 2022

Conversation

yez
Copy link
Contributor

@yez yez commented Oct 5, 2022

@schneems thanks for the opportunity to contribute!

Description

Adds two new tables: repo_labels and labels to store label data

Created a new service class to store and associate labels for repos
if the same label exists on multiple repos, it does not make
duplicate label records.

Add simple rake task to iterate through all repos in_batches and fetch one by one

Related Issue

Partially resolved #1680

Motivation and Context

People should be able to target Hacktoberfest

How Has This Been Tested?

Some simple integration testing of the newly created PORO

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Adds two new tables: `repo_labels` and `labels` to store label data

Created a new service class to store and associate labels for repos
  if the same `label` exists on multiple `repos`, it does not make
  duplicate `label` records.

Add simple rake task to iterate through all `repos` `in_batches` and
fetch one by one
return unless github_bub_response.success?

remote_labels.each do |label_hash|
label_name = label_hash['name'].downcase
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue stated that we wanted to only store hacktoberfest related labels. I'm happy to add a next unless line here if that's still the case but this is pretty simple as is.

desc 'fetch and assign labels for repos'
task fetch_labels_and_assign: :environment do
Repo.find_each(batch_size: 100) do |repo|
RepoLabelAssigner.new(repo: repo).create_and_associate_labels!
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I considered creating a new background job here and enqueueing it for 10 repos at a time but worried about rate-limiting and not knowing the concurrency of background processing in production. I also wasn't sure what the total count of repos in production was.

Copy link
Member

Choose a reason for hiding this comment

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

Repo count is on the main page it's ~6,000. The way we do API requests is that we rotate through everyone's tokens on the service for each request.

GitHubBub::Request.set_before_callback do |request|
if request.token?
# Request is authorized, do nothing
else
request.token = code_triage_random_api_key_store.call
end
end

It's a good idea not to make a bunch of extra requests, but we're not that constrained. If this is N API requests where N is the number of repos in the system, that's absolutely no problem.


require 'test_helper'

class RepoLabelsAssignerTest < ActiveSupport::TestCase
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Outside of my comfort zone here (I'm used to RSpec) so if this needs to change please let me know!

Copy link
Member

@schneems schneems left a comment

Choose a reason for hiding this comment

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

This is awesome, thanks a ton!

@schneems schneems merged commit 7bbfeb0 into codetriage:main Oct 5, 2022
@yez
Copy link
Contributor Author

yez commented Oct 5, 2022

@schneems thanks for accepting! It seems like Hacktoberfest wants you to add hacktoberfest-accepted label to this PR for it to count unfortunately. I'll be sure to add the following PRs with the scoping functionality soon!

screenshot

@schneems
Copy link
Member

schneems commented Oct 5, 2022

Updated

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

Successfully merging this pull request may close these issues.

Support targeting repos with specific label like #hacktoberfest
2 participants