Skip to content

Conversation

jmcgill
Copy link

@jmcgill jmcgill commented Aug 26, 2021

This change adds APIs for managing pull requests and comments on pull requests.

It also adds a Rake task that we will run every evening to sync Pull Requests

end

def create_user()
return User.create!({
Copy link

Choose a reason for hiding this comment

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

Don't need to add this to the database - this slows down the test suite

describe "#index" do
it "returns something" do
get :index
expect(response).not_to be_empty
Copy link

Choose a reason for hiding this comment

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

This is a great test to start with, but it doesn't test real product behavior, so it needs to evolve a little.

describe PullRequestsController do
before do
user = create_user
allow(controller).to receive(:current_user).and_return(user)
Copy link

Choose a reason for hiding this comment

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

Note to self, do we want this here ?


describe PullRequestsController do
before do
user = create_user
Copy link

Choose a reason for hiding this comment

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

If we're using rspec, let will be ... More elegant.

@@ -0,0 +1,100 @@
desc 'Sync pull requests from Github'
task :sync => :environment do
Copy link

Choose a reason for hiding this comment

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

In six months I think you'll find yourself typing rake sync and wondering which of twelve syncs we're running. I would recommend a slightly more descriptive name, maybe even a nested thing - rake sync:github:pr might be an extreme example.

@@ -0,0 +1,100 @@
desc 'Sync pull requests from Github'
task :sync => :environment do
class ResponseError < StandardError
Copy link

Choose a reason for hiding this comment

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

A part of me is surprised this isn't defined somewhere else in the codebase already - these error names are very generic and high level, so we want one of two things here:

  1. either we make task-specific error names
  2. either we move these out so the whole codebase can use these as common errors

If you're not sure which of the two to do, then let me know and we can have a conversation about it - you'll be able to make the decision afterwards.

@repository = repository
end

# These errors seem to happen a lot, so avoid sending them to Bugsnag
Copy link

Choose a reason for hiding this comment

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

..... why do these errors happen a lot?

Errors are a way for the server to communicate with us, so if we're doing something wrong, we probably shouldn't ignore it. Here, it seems to indicate we're asking for too much too fast. We should look for a tool that helps us stay within the acceptable bounds as defined by Github's API terms of use.

attr_reader :response, :repository
end

BadGatewayError = Class.new(ResponseError)
Copy link

Choose a reason for hiding this comment

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

I like this! Simple, concise, and super-clear.

).new(response, message, repository)
end

def response
Copy link

Choose a reason for hiding this comment

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

This name is too generic, and it hides the fact that this code is making the HTTP call. I would suggest something like current_pull_requests_on_github (or whatever makes more sense) so that the next person reading this code is tipped off to the idea that an HTTP call is happening.


@pull_requests = @pull_requests.tagged_with(params[:tag]) if params[:tag].present?

@pull_requests = @pull_requests.order(created_at: :desc).offset(params[:offset] || 0).limit(params[:limit] || 20)
Copy link

Choose a reason for hiding this comment

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

These three definitions of @pull_requests here look like they are business logic (which PRs do we want and how?) and that is usually best handled by a scope in the model, rather than defined in the controller itself (bonus: much easier to test!).

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