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

Interface elements to support Github personal access tokens #2061

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

brandonfranzke
Copy link

@brandonfranzke brandonfranzke commented Jan 26, 2024

Added interface button in Account page next to the "Connect to Github" button - "Use Personal Access Token". Clicking takes to a single field form to manually (copy-paste) token. This uses the same tables as the existing github_integration and applies the same encryption through ActiveRecord.

Note: you can set the token without progressing through the Oauth flow so this avoids having to approve the permissions per Issue #2059 .

There are no tests so understand if you dont Accept the PR, but it should be proof of concept enough to allow others to easily implement the feature fully.

Summary

Summary generated by Reviewpad on 26 Jan 24 01:14 UTC

This pull request adds a button to set a Github token for user authentication. It includes changes to the users controller, views, and routes. Specifically, it adds methods for showing and submitting a Github token form, as well as updating the Github integration with the new token. This allows users to use their personal access token for Github interactions.

Description

Motivation and Context

How Has This Been Tested?

No, see above.

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:

  • I have run rubocop and erblint for style check. If you haven't, run overcommit --install && overcommit --sign to use pre-commit hook for linting
  • My change requires a change to the documentation, which is located at Autolab Docs
  • I have updated the documentation accordingly, included in this PR

Other issues / help required

If unsure, feel free to submit first and we'll help you along.

Copy link
Contributor

coderabbitai bot commented Jan 26, 2024

Walkthrough

Walkthrough

The recent update introduces functionality for integrating GitHub with user accounts. It allows users to update their GitHub access tokens directly through a dedicated form. This integration is facilitated by adding new actions in the UsersController for displaying and submitting the token form, alongside corresponding views for the form and a GitHub Settings section in the user profile. Routes for these new actions have also been established, ensuring users can easily navigate to and from the token update interface.

Changes

File(s) Change Summary
.../users_controller.rb Added show_github_token_form and submit_github_token_form actions with authorization.
.../views/users/github_token.erb Introduced a form for updating GitHub access token.
.../views/users/show.html.erb Added "Github Settings" section with link for GitHub token integration.
config/routes.rb Routes added for GitHub token form display and submission.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@reviewpad reviewpad bot requested a review from damianhxy January 26, 2024 01:14
@reviewpad reviewpad bot added small Pull request is small waiting-for-review labels Jan 26, 2024
<% @title = "Github Access Token" %>

<h2>Github Update Access Token</h2>
<% if GithubIntegration.connected %>
Copy link
Contributor

Choose a reason for hiding this comment

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

The conditional check GithubIntegration.connected is used to determine if the GitHub integration is connected. However, this might not correctly reflect the individual user's connection status since it seems to be checking a class-level property rather than an instance-level property related to the current user.

Consider modifying this to check the GitHub integration status for the specific user instance to ensure accurate display logic.

<div class="input-field">
<%= form.text_field :access_token, required: true %>
<%= form.label :access_token, "Access Token" %>
<span class="helper-text">Helpful description here</span>
Copy link
Contributor

Choose a reason for hiding this comment

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

The helper text under the access token input field is generic ("Helpful description here"). It would be beneficial to provide a more descriptive message to guide the user on where to find their GitHub access token or why it's needed.

Consider updating the helper text to provide clear instructions on obtaining a GitHub personal access token and its intended use.

Comment on lines +260 to +273
action_auth_level :github_token_form, :student
def submit_github_token_form
github_integration = GithubIntegration.find_by(user_id: @user.id)
access_token = params[:access_token]

if github_integration.nil?
github_integration = GithubIntegration.create!(access_token:, user: @user)
else
github_integration.update!(access_token:)
end

flash[:success] = "Updated Github Token"
redirect_to(user_path)
end
Copy link
Contributor

Choose a reason for hiding this comment

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

The submit_github_token_form action properly handles both the creation of a new GithubIntegration instance for the user if one does not already exist, and the updating of an existing instance with the new access token. The use of create! and update! methods ensures that any errors during these operations will raise exceptions, which is appropriate for catching unexpected issues.

However, there's no explicit handling of potential exceptions that could arise from the create! or update! operations, which could lead to a poor user experience if the database operations fail.

Consider adding error handling around the database operations to gracefully handle any exceptions and provide meaningful feedback to the user.

@damianhxy
Copy link
Member

Thank you for the PR - we'll take a look at it and reach out if we have questions!

(if you could give us permissions to push to your fork, we'll be able to make changes directly to this branch)

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.

3 participants