Git Product home page Git Product logo

github-app-template's Introduction

⚠️ Note: This repository is not maintained. For more recent guides about how to build GitHub Apps, see "About writing code for a GitHub App."

You can use this GitHub App template code as a foundation to create any GitHub App you'd like. You can learn how to configure a template GitHub App by following the archived "Setting up your development environment" guide.

Install

To run the code, make sure you have Bundler installed; then enter bundle install on the command line.

Set environment variables

  1. Create a copy of the .env-example file called .env.
  2. Add your GitHub App's private key, app ID, and webhook secret to the .env file.

Run the server

  1. Run ruby template_server.rb on the command line.
  2. View the default Sinatra app at localhost:3000.

github-app-template's People

Contributors

dependabot[bot] avatar francisfuzz avatar rachmari avatar rick avatar skedwards88 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

github-app-template's Issues

Add comments to .env-example file

It might be helpful to add comments to each of the variables in the .env-example file that describes what to add for each variable and when quotes are necessary (for multi-line variables).

Getting Argument error

When I try to follow the tutorial to setup development environment, Im getting the following error/usr/local/lib/ruby/gems/3.1.0/gems/mustermann-1.0.3/lib/mustermann/regular.rb:22:in initialize': wrong number of arguments (given 2, expected 1) (ArgumentError)
from /usr/local/lib/ruby/gems/3.1.0/gems/mustermann-1.0.3/lib/mustermann/pattern.rb:59:in new' from /usr/local/lib/ruby/gems/3.1.0/gems/mustermann-1.0.3/lib/mustermann/pattern.rb:59:in block in new'
from /usr/local/lib/ruby/gems/3.1.0/gems/mustermann-1.0.3/lib/mustermann/equality_map.rb:43:in fetch' from /usr/local/lib/ruby/gems/3.1.0/gems/mustermann-1.0.3/lib/mustermann/pattern.rb:59:in new'
from /usr/local/lib/ruby/gems/3.1.0/gems/mustermann-1.0.3/lib/mustermann.rb:67:in new' from /usr/local/lib/ruby/gems/3.1.0/gems/mustermann-1.0.3/lib/mustermann.rb:70:in block in new'
from /usr/local/lib/ruby/gems/3.1.0/gems/mustermann-1.0.3/lib/mustermann.rb:70:in map' from /usr/local/lib/ruby/gems/3.1.0/gems/mustermann-1.0.3/lib/mustermann.rb:70:in new'
from /usr/local/lib/ruby/gems/3.1.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1641:in compile' from /usr/local/lib/ruby/gems/3.1.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1629:in compile!'
from /usr/local/lib/ruby/gems/3.1.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1271:in error' from /usr/local/lib/ruby/gems/3.1.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1838:in class:Base'
from /usr/local/lib/ruby/gems/3.1.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:894:in <module:Sinatra>' from /usr/local/lib/ruby/gems/3.1.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:22:in <top (required)>'
from /usr/local/lib/ruby/gems/3.1.0/gems/sinatra-2.0.4/lib/sinatra/main.rb:1:in require' from /usr/local/lib/ruby/gems/3.1.0/gems/sinatra-2.0.4/lib/sinatra/main.rb:1:in <top (required)>'
from /usr/local/lib/ruby/gems/3.1.0/gems/sinatra-2.0.4/lib/sinatra.rb:1:in require' from /usr/local/lib/ruby/gems/3.1.0/gems/sinatra-2.0.4/lib/sinatra.rb:1:in <top (required)>'
from template_server.rb:1:in require' from template_server.rb:1:in

'`

401 - A JSON web token could not be decoded when following App example

Expected Behavior

I am following the example of using GitHub API's in a GitHub app. This page links to another page showing how to setup the development environment to do this.
I followed the instructions on that page, with one difference, for testing, I kept the contents of the pem file in the code 64-encoded. The code then proceeds to decode that string to get the actual content of the pem file, and use that to construct the PRIVATE_KEY. So, it looks like this

  PRIVATE_KEY_ENCODED = "some long string"
  PRIVATE_KEY_DECODED = (Base64.decode64(PRIVATE_KEY_ENCODED)).gsub('\n', "\n")
  PRIVATE_KEY = OpenSSL::PKey::RSA.new(PRIVATE_KEY_DECODED)

Actual Behavior

When I install the GitHub app in a new organization, I the following error:
POST https://api.github.com/app/installations/27776345/access_tokens: 401 - A JSON web token could not be decoded // See: https://docs.github.com/rest (Octokit::Unauthorized).

This error occurs when the code tries to get the token of a specific installation
@installation_token = @app_client.create_app_installation_access_token(@installation_id)[:token]

Steps to Reproduce

Follow instructions in https://docs.github.com/en/developers/apps/getting-started-with-apps/setting-up-your-development-environment-to-create-a-github-app.

Context

In testing the code, in a Ruby console, I debugged the ran the template_server.rb file and placed a binding.pry right before the error is thrown.
I did the following:

# This is taken from https://github.com/github-developer/github-app-template/blob/master/template_server.rb#L94

payload = {
          # The time that this JWT was issued, _i.e._ now.
          iat: Time.now.to_i,

          # JWT expiration time (10 minute maximum)
          exp: Time.now.to_i + (10 * 60),

          # Your GitHub App's identifier number
          iss: APP_IDENTIFIER
      }

# Calculate a jwt
jwt = JWT.encode(payload, PRIVATE_KEY, 'RS256')

# display the installation id
@installation_id

Then I ran the following cURL command in a command line.

curl -i -X POST
-H "Authorization: Bearer "
-H "Accept: application/vnd.github+json"
https://api.github.com/app/installations/<@installation_id>/access_tokens

I received a valid response that did include a token. So, it doesn't seem that the problem is in the code itself, but that for some reason the Octokit::Client is not doing the right thing in calling the intended API.

Run the template error:uninitialized constant Faraday

Follow this guide https://docs.github.com/en/developers/apps/getting-started-with-apps/setting-up-your-development-environment-to-create-a-github-app and get error when i try to start the server in step 6

➜  github-app-template git:(master) ✗ bundle exec ruby template_server.rb
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/universal-darwin20/rbconfig.rb:229: warning: Insecure world writable dir /usr/local/go/bin in PATH, mode 040777
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/universal-darwin20/rbconfig.rb:229: warning: Insecure world writable dir /usr/local/go/bin in PATH, mode 040777
Traceback (most recent call last):
        8: from template_server.rb:2:in `<main>'
        7: from template_server.rb:2:in `require'
        6: from /Library/Ruby/Gems/2.6.0/gems/octokit-4.13.0/lib/octokit.rb:4:in `<top (required)>'
        5: from /Library/Ruby/Gems/2.6.0/gems/octokit-4.13.0/lib/octokit.rb:4:in `require'
        4: from /Library/Ruby/Gems/2.6.0/gems/octokit-4.13.0/lib/octokit/default.rb:1:in `<top (required)>'
        3: from /Library/Ruby/Gems/2.6.0/gems/octokit-4.13.0/lib/octokit/default.rb:1:in `require'
        2: from /Library/Ruby/Gems/2.6.0/gems/octokit-4.13.0/lib/octokit/middleware/follow_redirects.rb:9:in `<top (required)>'
        1: from /Library/Ruby/Gems/2.6.0/gems/octokit-4.13.0/lib/octokit/middleware/follow_redirects.rb:11:in `<module:Octokit>'
/Library/Ruby/Gems/2.6.0/gems/octokit-4.13.0/lib/octokit/middleware/follow_redirects.rb:14:in `<module:Middleware>': uninitialized constant Faraday::Error::ClientError (NameError)
Did you mean?  Faraday::ClientError

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.