CSC/ECE 517 Fall 2021 - E2149. Finish Github metrics integration - Reputations

From Expertiza_Wiki
Jump to navigation Jump to search

Abstract

Expertiza provides teammate reviews to measure how much each team member contributed. It also augments this data with Github data of each group’s submitted repo link to help differentiate the performance of team members for grading purposes and predict which projects are likely to be merged. Instructors would like to compile this Github repository statistics on a per-project, per-team basis, and integrate the display of these data within Expertiza. The project team will troubleshoot existing code and add new features.

Problem Statement

The functionality of the showing GitHub metrics cannot be turned off, meaning that an instructor who uses Expertiza for writing assignments in an English course would get a Github metrics report. There needs to be a way to turn the report off for a particular assignment. The project doesn't report lines added and deleted because of the lack of support from the current API. It adds quite a lot of lines of code for a single project and some codes could be refactored. The test plans of the current project are not described thoroughly enough. We will modify the existing RSpec test code and add some new tests.

Methodology

The team has synced the revised 2021 Spring project E2111 code with the current status of the Expertiza/beta branch and has begun analyzing the existing code. Prior customer feedback has advised the team to address inextensibility/coupling issues, documentation issues, and synchronization issues. We are performing our own end-to-end analysis of the code in addition to this feedback, and have found numerous action items so far. We have separated these action items into Primary and Secondary objectives: Primary objectives are "must-haves" that need to be addressed before the existing code is mergeable. Secondary objectives are "nice-to-haves" or features that are either left out of the original project or will make the integration display more integrated.

Team Action Items

Adding turn on and turn down option

The functionality of the current project cannot be turned off. We will provide an option for instructors not to query Github metrics data before they post the assignment, which is the way we turn the GitHub report off for a particular assignment.

Database Modification

In order to determine whether the GitHub report of the assignment is turned on or turned off, we need to create a new table named "use_github_metric" to save the id of the assignment whose GitHub metric is turned on. We also have an alternative solution to add a boolean field in the assignment table, but due to security concerns, we give it up. We think we should not change the data of the assignment.

Table: use_github_metric

id(PK) Assignment_id(FK)
1 1
2 15


Simplify the Codes

Extract the repeating part of codes and then construct an independent method based on them. Finally, we could use this method.

The last edition uses the lots of Google API to help generate the chart, we can use the method from helper to generate charts instead.

Frontend Modification

If a user chooses not to include the GitHub metric in the assignment (the functionality is turned off), the icon named "Login to Query of Github data" should not be displayed on the frontend page.

We edited expertiza\app\views\assignments\edit\_general.html.erb and added a checkbox. The codes are as follow.

     <input type="checkbox" name = "use_github" id="use_github" <%= "checked" 
     if UseGithubMetricsController.exist(@assignment_form.assignment.id) %>></input>
     <%= label_tag('use_github', 'Use github metrics?') %>

Controller Modification

we will add two functions in the assignment_controller to query and update the status of using the Github metric.

def query_github_metric_status

this function will check whether the assignment_id is in the use_github_metric table. If not exist, the Github metric will be turned off. Otherwise, it will be turned on.

def update_github_metirc

this function will update the status of using the Github metric of assignment and flashes a notice. If the metric is turned on, we will add the assignment_id to the table use_github_metric. If it is turned off, we will delete the assignment_id from the table.

Testing

See the details in Test Plan.

Functionality Walk Through

Assignment edit page view

An instructor can customize an assignment in this view. We will provide an option for instructors to decide whether they need Github metrics in the assignment or not.

Before we modified this part, this page is as follows:

After modifying it, this page is:

List Submissions View: with Github metrics option

This is how a user will view List Submissions when they choose Github metrics in the previous assignment edit page and is not authenticated to Github yet. The Login link redirects to an omniauth login page, which redirects back to this page.


List Submissions View: without Github metrics option

This is how a user will view List Submissions when they did not choose Github metrics in the previous assignment edit page. The Login link for querying Github data would not be provided to the instructors if they don't choose the "use GitHub metric" option.

Final Design UML

This UML shows the new classes and models we created and implemented in our final project. Besides these, we also modified some of the existing classes and methods, we will give more detailed information later.

OminiAuth Github API update

GitHub no longer supports authentication through query parameters. Thus, we move the authentication to the header. From September 8, 2021, using access_token as a query parameter to access the API (as a user or as a GitHub App) and using client_id/client_secret to make OAuth app unauthenticated are disabled.

Using access_token as a query param

Originally, the code uses the API with parameters。

curl "https://api.github.com/user/repos?access_token=my_access_token"

Now, we send the token in the header:

curl -H 'Authorization: token my_access_token' https://api.github.com/user/repos

Using client_id/client_secret as a query param

Originally, the code uses an OAuth app's client_id and client_secret to make unauthenticated calls with a higher rate limit similar to

curl "https://api.github.com/user/repos?client_id=my_client_id&client_secret=my_secret_id"

Instead, we use the following format:

curl -u my_client_id:my_client_secret https://api.github.com/user/repos

Test Plan

UI Testing

Our UI tests aim to capture the following core pieces of functionality:

Turn on and turn down functionality button:

In order to test the functionality manually, we follow the following steps:

1. Log in to Expertiza as an instructor
2. Navigate to assignments through Manage
3. Show a turn on/turn down option for Github metric on the page
4. Process the page without choosing Github metrics report for a particular assignment
5. The page should not display "Login to Query of Github data" options.


Rspec

Detailed of Github Testing

After changing the way of calling the GitHub API, we need to test whether we can get the data from the GitHub API correctly.

describe '#gets data from GitHub api v4(graphql)' do
end
describe '#get_github_repository_details' do
end
describe '#get_statuses_for_pull_request' do
end

Resources

Key Links

Github API Documentation

Deprecating API authentication through query parameters

Previous Project References

Original E1858 Documentation

E1983 Revision Documentation

E2111 Project Refactoring