CSC/ECE 517-GH-2401-Rest-GraphQL-Endpoints

From Expertiza_Wiki
Jump to navigation Jump to search

Live Demo

Link

About

The project involves developing API endpoints for GitHub GraphQL queries and GitHub REST queries and to integrate these endpoints into the Python Flask framework, enabling the publication of these queries as accessible API endpoints via URLs. We have implemented endpoints for 4 query elements: comment, contributions, profiles and time_range_contributions. Each element contains multiple queries and each query has a separate endpoints for both GraphQL and REST API implemented.

Setup

Software Requirements

  • Python 3.9 or above
  • Git
  • VSCode
  • formatter plugin (autopep8)
  • Docker

Steps

GITHUB_OAUTH_CLIENT_ID=<your client id>

GITHUB_OAUTH_CLIENT_SECRET=<your client secret>

SECRET_KEY=<any string but empty not allowed>

MYSQL_DATABASE_PASSWORD=<your password>

  • Open the project folder and build the docker image using the following command

docker build -t gh_miner .

  • To run the docker image

docker run -p 5000:5000 gh_miner

The "-p 5000:5000" is for port forwarding the 5000 port. You can also use "-d" argument in the command to run the image in background

Optionally, if you want to run without docker, you can follow the below steps

  • Open up terminal in the project folder "GH_Miner"
  • Create a python virtual environment and activate it

python -m venv venv

  1. If you're on windows

.\venv\Scripts\Activate

  1. If you're on linux / Mac

source ./venv/bin/activate

  • Install all the dependencies

pip install -r requirements.txt

  • Run the backend flask app

python -m backend.run

Endpoints

Below are the endpoints implemented in the flask backend

Firstly The user needs to authenticate inorder to access the API

Authentication

Login

'/auth/login'

Visiting this endpoint will take the user to github login page, once authenticated the user will be redirected to /index page

Logout

'/auth/logout'

To terminate the current session, user can visit this endpoint

View Current User

The below endpoint returns the login name of the currently authenticated user

'/api/graphql/current-user-login'

{
  "viewer": {
    "login": "omjain2001"
  }
}

Comments

User Gists

This query returns the comments in gists of the authenticated user.

GraphQL Endpoint

'/api/graphql/user-gist-comments/'

{
[
  {
    "user": {
      "gistComments": {
        "nodes": [],
        "pageInfo": {
          "endCursor": null,
          "hasNextPage": false
        },
        "totalCount": 0
      },
      "login": "omjain2001"
    }
  }
]
}

REST Endpoint

'/api/rest/user-gist-comments/'

{
[
  {
    "login": "omjain2001",
    "pageInfo": {
      "hasNextPage": false,
      "totalCount": 0
    },
    "user": {
      "gistComments": {
        "nodes": []
      }
    }
  }
]
}


User Commits

This query returns the comments in all commits of the authenticated user.

GraphQL Endpoint

'/api/graphql/user-commit-comments/'

{
[
  {
    "user": {
      "commitComments": {
        "nodes": [],
        "pageInfo": {
          "endCursor": null,
          "hasNextPage": false
        },
        "totalCount": 0
      },
      "login": "omjain2001"
    }
  }
]

}

REST Endpoint

'/api/rest/user-commit-comments/'


User Issues

This query returns the comments in issues and pull requests of all public repositories of the authenticated user.

GraphQL Endpoint

'/api/graphql/user-issue-comments'

{
[
  {
    "user": {
      "issueComments": {
        "nodes": [],
        "pageInfo": {
          "endCursor": null,
          "hasNextPage": false
        },
        "totalCount": 0
      },
      "login": "omjain2001"
    }
  }
]

}

REST Endpoint

'/api/rest/user-issue-comments'

{
[
  {
    "login": "omjain2001",
    "pageInfo": {
      "hasNextPage": false,
      "totalCount": 7
    },
    "user": {
      "issueComments": {
        "nodes": [
          {
            "created_at": "2021-08-31T12:46:01Z"
          },
          {
            "created_at": "2021-08-31T12:46:02Z"
          },
          {
            "created_at": "2021-08-31T13:38:09Z"
          }
        ]
      }
    }
  }
]
}

User Repository Discussions

This query returns the comments in the repository discussions of the authenticated user. For the REST query, there is no REST query to fetch repository discussions, hence this endpoint does not return any results.

GraphQL Endpoint

'/api/graphql/user-repository-discussions'

Contributions

User Gists

This query returns the gists of the authenticated user.

GraphQL Endpoint

'/api/graphql/user-gists/<username>'

REST Endpoint

'/api/rest/user-gists/<username>'


User Issues

This query returns the issues of the authenticated user.

GraphQL Endpoint

'/api/graphql/user-issues/<username>'

REST Endpoint

'/api/rest/user-issues/<username>'


User Pull Requests

This query returns the pull requests of the authenticated user. For the REST query, we can only fetch pull requests for a particular repository for the authenticated user.

GraphQL Endpoint

'/api/graphql/user-pull-requests/<username>'

REST Endpoint

'/api/rest/user-pull-requests/<username>/<repo>'


User Repositories

This query returns the repositories of the authenticated user.

GraphQL Endpoint

'/api/graphql/user-repositories/<username>'

REST Endpoint

'/api/rest/user-repositories/<username>'

User Repository Discussions

This query returns the repository discussions of the authenticated user. For the REST query, there is no REST query to fetch repository discussions, hence this endpoint does not return any results.

GraphQL Endpoint

'/api/graphql/user-repository-discussions/<username>'

REST Endpoint

'/api/rest/repository-discussions/<username>/<repo>'

Profiles

This endpoint returns all the profile statistics (followers, gists, issues, pull requests, repositories, etc.) of the required user. The user must specify the username in this query.

GraphQL Endpoint

'/api/graphql/user-stats/<username>'

REST Endpoint

'/api/rest/user-stats/<username>'

{

  "commit_comments": 0,
  "company": "omjain2001",
  "created_at": "2020-02-03T10:55:04Z",
  "followers": 11,
  "following": 0,
  "gist_comments": 0,
  "gists": 0,
  "github": "omjain2001",
  "issue_comments": 0,
  "issues": 0,
  "projects": 1,
  "pull_requests": 8,
  "repositories": 26,
  "starred_repositories": 1,
  "watching": 21
}

Time Range Contributions

This endpoint returns all the details of the user contributions within a specified duration. The user must specify the username, start date, and end date in this query.

GraphQL Endpoint

'/api/graphql/user-contributions/<username>'

{
  "commit": 37,
  "issue": 0,
  "pr": 8,
  "pr_review": 1,
  "repository": 4,
  "res_con": 0
}


REST Endpoint

'/api/rest/user-contributions/<username>'

Query Params

  • start: DateTime (ISO 8601 format)
  • end: DateTime (ISO 8601 format)
{
  "commit": 0,
  "issue": 0,
  "pr": 0,
  "pr_review": 6,
  "repository": 30,
  "res_con": 0
}