Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Dashboard for Teachers (time of the last push & build status) #708

Closed
wants to merge 44 commits into from

Conversation

cyhsutw
Copy link
Contributor

@cyhsutw cyhsutw commented Aug 18, 2016

Part of #613.

This pull request adds functionality for teachers to check the time of the last push and the build status of the latest commit.

Preview:

preview

Edit: This feature is now placed under Flipper teacher_dashboard flag.

Would love to hear you feedback! Thanks 😄

@cyhsutw cyhsutw added ready for review WIP 💭 PR's that are a 'Work In Progress' and removed ready for review labels Aug 18, 2016
@cyhsutw
Copy link
Contributor Author

cyhsutw commented Aug 18, 2016

Currently, this function will cost a lot of time for the pages to load, I'll change the implementations using AJAX.

@cyhsutw cyhsutw added ready for review and removed WIP 💭 PR's that are a 'Work In Progress' labels Aug 19, 2016
@cyhsutw cyhsutw closed this Aug 19, 2016
@cyhsutw cyhsutw reopened this Aug 19, 2016
@nwoodthorpe
Copy link
Contributor

Hey @cyhsutw how close is this to being finished? I'd love to see this get merged, it looks great from what I can see.

@nwoodthorpe
Copy link
Contributor

Closing for now, feel free to re-open if there's progress.

@cyhsutw
Copy link
Contributor Author

cyhsutw commented May 25, 2017

@nwoodthorpe Thanks for the heads-up. I've merged master into this and made necessary modifications. Please review it at your convenience. 😄

@cyhsutw cyhsutw reopened this May 25, 2017
@@ -52,7 +52,9 @@
end

after(:build) do |organization, evaluator|
create_list(:user, evaluator.users_count, organizations: [organization])
if evaluator.users.count < evaluator.users_count
create_list(:user, evaluator.users_count, organizations: [organization])
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 added this check because this is adding random extra users to the organization.

This will break the functionality of Organization#github_client since the access_token of the randomly created user is not valid, which will make the API calls return 401.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, could you explain this a bit more? What's creating random users in the organization?

Having to edit this random unrelated line of code that's been fine for 2 months worries me a little bit

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'll try my best to explain it.

So this line of code will generate a list of users with length equals to evaluator.users_count, and the users are generated using this factory.

This is totally okay if we don't access any of the users generated by this line of code (and yes, there isn't a line in the codebase that does this). However, if we try to use any of the access tokens that are associated with these users to call GitHub APIs, it simply fails as these are just some random hex string.

This line of code will create a new user even if we already specified users to be associated with the organization (e.g. GitHubFactory#classroom_org).

This is the issue I faced when I run test examples:

let(:organization) { classroom_org }
# => organization.users.size  <--- this is 2!

In this case, you can only get a working organization.github_client on a 50% chance.

IMHO the reason we have this line of code is to ensure that there's at least one user in an organization, we don't need to add another user if we already got one. That's the reason I made this change.

Please let me know if there's anything I can help. Thanks! 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, because a token is chosen from a random user. In that case, this makes sense to me.

@nwoodthorpe
Copy link
Contributor

Thanks for getting this sorted! It's a pretty hefty diff, I'll try to find some time today to step through it.

@@ -0,0 +1,41 @@
# frozen_string_literal: true

module GitHubRepoStatus
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for using a concern here. Assignment and group-assignment are super similar, we should be using these more often.


def latest_push_event(repo_id, options = { per_page: 100, page: 1 })
events = event_client.repository_events(repo_id, options).select do |event|
event.type == 'PushEvent' ||
Copy link
Contributor

Choose a reason for hiding this comment

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

These can be on the same line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👌

(event.type == 'CreateEvent' && event.payload.ref.present?)
end

events.length.positive? ? events.first : nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason for this vs #empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch! Should have used #empty for this.

I'm going to simplify this further using #first only as the result will be the same according to the docs.

@@ -52,7 +52,9 @@
end

after(:build) do |organization, evaluator|
create_list(:user, evaluator.users_count, organizations: [organization])
if evaluator.users.count < evaluator.users_count
create_list(:user, evaluator.users_count, organizations: [organization])
Copy link
Contributor

Choose a reason for hiding this comment

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

Right, because a token is chosen from a random user. In that case, this makes sense to me.

@nwoodthorpe
Copy link
Contributor

This looks really good to me! Thanks for finishing this up

@nwoodthorpe
Copy link
Contributor

Also I'd like to squash before we merge. You don't have to worry about it yet though.

@cyhsutw
Copy link
Contributor Author

cyhsutw commented May 26, 2017

@nwoodthorpe Thanks for reviewing! I've updated the code to resolve the issues you spotted, please have a 👀 .

Also I'd like to squash before we merge.

+1 on this. Would you like me to do that or this can be done using the squash on merge feature on GitHub?

@nwoodthorpe
Copy link
Contributor

Code LGTM

Yeah, squash on merge should be fine. @johndbritton for review

@stale
Copy link

stale bot commented Jul 25, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot closed this Aug 2, 2017
@tarebyte tarebyte deleted the dashboard-for-teacher branch October 20, 2017 00:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants