Giter Site home page Giter Site logo

github / platform-samples Goto Github PK

View Code? Open in Web Editor NEW
1.9K 633.0 1.7K 7.52 MB

A public place for all platform sample projects.

License: Creative Commons Zero v1.0 Universal

Ruby 21.65% HTML 4.54% Shell 31.35% Groovy 5.86% JavaScript 17.90% Scala 5.15% Python 4.98% Java 1.72% Dockerfile 0.11% Perl 4.83% Go 1.03% Batchfile 0.02% PowerShell 0.87%
ruby sample graphql pre-receive-hooks javascript hooks platform platform-samples

platform-samples's Introduction

platform-samples

This is a public place for all sample projects related to the GitHub Platform.

Hierarchy

The directories are organized to correlate with guides found on developer.github.com. But here it is, broken down:

  • api: here's a bunch of sample code relating to the GitHub API. Subdirectories in this category are broken up by language. Do you have a language sample you'd like added? Make a pull request and we'll consider it.
  • graphql: here's a bunch of sample GraphQL queries that can be run against our GitHub GraphQL API.
  • hooks: want to find out how to write a consumer for our web hooks? The examples in this subdirectory show you how. We are open for more contributions via pull requests.
  • microsoft-graph-api: here's a bunch of sample Microsoft Graph commands related to integrations for GitHub, such as EMU (Enterprise Managed User) OIDC authentication for Azure AD/Entra.
  • pre-receive-hooks: this one contains pre-receive-hooks that can block commits on GitHub Enterprise that do not fit your requirements. Do you have more great examples? Create a pull request and we will check it out.
  • scripts: want to analyze or clean-up your Git repository? The scripts in this subdirectory show you how. We are open for more contributions via pull requests.
  • sql: here are sql scripts for custom reporting for GitHub Enterprise Server. We are open for more contributions via pull requests.

platform-samples's People

Contributors

admiralawkbar avatar azizshamim avatar cjs avatar dependabot[bot] avatar djdefi avatar evgenyrahman avatar georgicodes avatar github-actions[bot] avatar gjtorikian avatar homeles avatar iamhughes avatar izuzak avatar jasonrudolph avatar jbjonesjr avatar jefeish avatar jgkite avatar jonico avatar larsxschneider avatar mzzmjd avatar nathos avatar pholleran avatar ppremk avatar ramonpage avatar sarahs avatar sn2b avatar some-natalie avatar stacycarter avatar stoe avatar tcbyrd avatar whatupfoo 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

platform-samples's Issues

jira pre-receive hook isn't working on the server end

i just added the https://github.com/github/platform-samples/blob/master/pre-receive-hooks/require-jira-issue.sh script to one of my github remote repos and was able to successfully configure a pre-receive hook at the org level and enabled it for one of my sample repos. Now when i push to that sample repo from local, it always results in the below error :-
remote: jira-commit-hook.sh: failed with exit status 1
remote: grep: Invalid range end
remote: ERROR:
remote: ERROR: Your push was rejected because the commit
remote: ERROR: e9b0dd4695a51beb51e6fc1a8d16f01fa7dd13b8 in master
remote: ERROR: is missing the JIRA Issue
remote: ERROR:
remote: ERROR: Please fix the commit message and push again.

! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://************'

The commit regex i'm using is msg_regex='[DST-[0-9]+]' since DST is the project key in our jira for one of the projects. All the commits i am pushing has the string DST-*** in their message where *** is a number and DST-*** is some actual issue key for the jira project here. Any idea why the remote server hook is rejecting the push. Looks like its not validating the regex. Any idea why?

Add query that lists SAML external identities for an Organization

Business Plan hosted customers with SAML would like a way to programmatically query information about a GitHub user account's SAML identity. The following is a GraphQL query that accomplishes this for an Organization.

query {
  organization(login: "LOGIN") {
    samlIdentityProvider {
      ssoUrl
      externalIdentities(first: 100) {
        edges {
          node {
            guid
            samlIdentity {
              nameId
            }
            user {
              login
            }
          }
        }
      }
    }
  }
}

/cc @francisfuzz as you might be able to track down the author to see if they want to add this ☝️

the block confidential script is not blocking the kubeconfig file

Hello experts,

We are using the platform samples the block confidential pre-receive script in our environment. It was working as expected.
but when we scanned the GitHub data , we could identify that the kubeconfig files are not getting blocked.

Could you please suggest us to add the best regex to find the kubeconfig file and block it through pre-receive script..

Bash Script Examples

Based on a discussion with GitHub Platform folks, GitHub Enterprise customers, as well as the Dot-Com community, will benefit from API examples using bash scripts. This repository serving as the "source of truth" curated resource could be helpful to everyone interested.

Examples of "getting started" scripts would include scenarios that take the developer.github.com/v3 examples beyond a one-line cURLs. @brntbeer listed some samples over here.

Following the pattern already established in this repo for Ruby, api/bash/ would be a great place for these bash scripts to live and that the @github/services-implementationspecialists could contribute to.

We'll submit a PR just as soon as the github/platform-sample curators give us the πŸ‘.

undefined method `run' for HTTP:Module (NoMethodError) - sinatra 1.4.6

If you are using a new version of ruby and sinatra you will get an error:

$ ruby server.rb 
/home/santana/.rvm/gems/ruby-2.2.1/gems/sinatra-1.4.6/lib/sinatra/base.rb:1505:in `start_server': undefined method `run' for HTTP:Module (NoMethodError)
    from /home/santana/.rvm/gems/ruby-2.2.1/gems/sinatra-1.4.6/lib/sinatra/base.rb:1443:in `run!'
    from /home/santana/.rvm/gems/ruby-2.2.1/gems/sinatra-1.4.6/lib/sinatra/main.rb:25:in `block in <module:Sinatra>'

NOTE: How to fix it.

Getting more done in GitHub with ZenHub

Hola! @banasikz2016 has created a ZenHub account for the github organization. ZenHub is the only project management tool integrated natively in GitHub – created specifically for fast-moving, software-driven teams.


How do I use ZenHub?

To get set up with ZenHub, all you have to do is download the browser extension and log in with your GitHub account. Once you do, you’ll get access to ZenHub’s complete feature-set immediately.

What can ZenHub do?

ZenHub adds a series of enhancements directly inside the GitHub UI:

  • Real-time, customizable task boards for GitHub issues;
  • Multi-Repository burndown charts, estimates, and velocity tracking based on GitHub Milestones;
  • Personal to-do lists and task prioritization;
  • Time-saving shortcuts – like a quick repo switcher, a β€œMove issue” button, and much more.

Add ZenHub to GitHub

Still curious? See more ZenHub features or read user reviews. This issue was written by your friendly ZenHub bot, posted by request from @banasikz2016.

ZenHub Board

ruby server.rb errors on active_support/all

ruby server.rb
/Users/kaltepe/.rvm/rubies/ruby-2.1.10/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:59:in require': cannot load such file -- active_support/all (LoadError) from /Users/kaltepe/.rvm/rubies/ruby-2.1.10/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:59:in require'
from server.rb:4:in `

'

I got this error when following the github guide: https://developer.github.com/apps/building-your-first-github-app/. I tried many versions of ruby and no dice. I had to add this to my Gemfile to make it work.

gem 'activesupport', '~> 5.0'

Not sure if anyone else had this happen.

script error in block secrete error messsage

when we tried to implement the hook script in our setup, with the block secrete error message its also showing some script error as given below. Please help.

"remote: /data/user/git-hooks/repos/110/hooks.sh: line 1: ο»Ώ#!/bin/bash: No such file or directory"

$ git push
Username for 'https://git.mydomain.com': uid
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (4/4), 344 bytes | 68.00 KiB/s, done.
Total 4 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
remote: hooks.sh: failed with exit status 1
remote: /data/user/git-hooks/repos/110/hooks.sh: line 1: ο»Ώ#!/bin/bash: No such file or directory
remote: 7:+-----BEGIN RSA PRIVATE KEY-----
remote:
remote: [POLICY BLOCKED] You're trying to commit a password, token, or confidential information
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.mydomain.com/demo.git'

Getting the user OAuth token

Sorry if i post this in the wrong place. But i have a question about the guide.

About this part of discovering_repositories.rb in "Discovering resources for a user":

client = Octokit::Client.new :access_token => ENV["OAUTH_ACCESS_TOKEN"]

Where do i get this access token? It's said that we already acquired the OAuth token for a given user, from the previous guide, "Basics of Authentication"

I obviously have my app's Client ID and Client Secret. But i don't think it's been shown before on how to get this access token. At least not one that i can copy-paste to replace the environment variable above.

Thx.

Pre-receive hook output prefix

Hi, in an organisation with many pre-receive hooks running, it would be great if the hook was executed with each stdout line being pre-fixed with the hook that caused the line output.

Like what is shown here: https://superuser.com/a/623119/860394

command1.sh | sed "s/^/[command1] /"
command2.sh | sed "s/^/[command2] /"

For hook maintainers, it is time consuming to constantly address questions about issues related to other hooks created by other teams within an organisation.

Edit:

per-hook solutions are welcome, though a GitHub-wide solution would be ideal.

404 thrown when accessing private repos for rendering-data-as-graphs

Errors are thrown in the rendering-data-as-graphs for two actions

  1. when attempting to access languages for a private repo
  2. when attempting to access languages for a repo the user doesn't own but is a collaborator too (in this case, the URL is constructed incorrectly). Really, this should be fixed properly so that the correct URL is constructed but for now, it should at least not throw a runtime exception.

require-jira-issue.sh is not working

Hi, I need to run this script in my hooks. But When I type git push. it sucessfully push the code without rejecting it.

My System Info:

Ubuntu 18.04.4 LTS

Git Version:
2.17.1

Environment variables GITHUB_APP_ID & GITHUB_APP_PRIVATE_KEY

Issue

I am doing the building your first github app guide, and in documentation at section runtime environment the variables have different naming than in code.

Vars on Guide

export GITHUB_APP_IDENTIFIER=12345
export GITHUB_PRIVATE_KEY= ...

Vars on Code

begin
  GITHUB_APP_ID = ENV.fetch("GITHUB_APP_ID")
  GITHUB_PRIVATE_KEY = ENV.fetch("GITHUB_APP_PRIVATE_KEY")
rescue KeyError
  $stderr.puts "To run this script, please set the following environment variables:"
  $stderr.puts "- GITHUB_APP_ID: GitHub App ID"
  $stderr.puts "- GITHUB_APP_PRIVATE_KEY: GitHub App Private Key"
  exit 1
end

Solution

Decide if the docs have to be changed or the code, if the code has to be changed I will be pleased to make a pull request to fix this.

Handle API errors

In repo-list-export.sh, we currently don't handle errors returned by the GitHub API (invalid org name, permissions/404, etc.)

Catching these and outputting a message to STDERR will improve the experience for users.

Errors during running find-inactive-members.rb and no output

I try to run the ruby script find-inactive-members.rb, but I get no output at all !
When I debug the ruby script I can see several errors.
Checking the syntax is OK

I also want to know what is the right syntax for the --date parameter?

ruby --version
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]
gem env version
2.7.6

I am running on windows wsl ubuntu 18.04.4 LTS (Bionic Beaver)

When I run ruby -v -d find-inactive-members.rb -cv -o kadaster-it -d 03/12/2020
I see the following output:

ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]
Exception LoadError' at /usr/local/lib/site_ruby/2.5.0/rubygems.rb:1397 - cannot load such file -- rubygems/defaults/ruby find-inactive-members.rb:85: warning: assigned but unused variable - email find-inactive-members.rb:230: warning: mismatched indentations at 'end' with 'def' at 191 Exception SyntaxError' at /usr/lib/ruby/2.5.0/forwardable/impl.rb:6 - : syntax error, unexpected end-of-input
().pos=
^
Exception SyntaxError' at /usr/lib/ruby/2.5.0/forwardable/impl.rb:6 - <compiled>: syntax error, unexpected end-of-input ().sync= ^ Exception LoadError' at /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59 - cannot load such file -- octokit
Exception SyntaxError' at /usr/lib/ruby/2.5.0/forwardable/impl.rb:6 - <compiled>: syntax error, unexpected end-of-input ().scheme= ^ Exception SyntaxError' at /usr/lib/ruby/2.5.0/forwardable/impl.rb:6 - : syntax error, unexpected end-of-input
().host=
^
Exception SyntaxError' at /usr/lib/ruby/2.5.0/forwardable/impl.rb:6 - <compiled>: syntax error, unexpected end-of-input ().port= ^ Exception SyntaxError' at /usr/lib/ruby/2.5.0/forwardable/impl.rb:6 - : syntax error, unexpected end-of-input
().path=
^
Exception SyntaxError' at /usr/lib/ruby/2.5.0/forwardable/impl.rb:6 - <compiled>: syntax error, unexpected end-of-input ().scheme= ^ Exception SyntaxError' at /usr/lib/ruby/2.5.0/forwardable/impl.rb:6 - : syntax error, unexpected end-of-input
().host=
^
Exception SyntaxError' at /usr/lib/ruby/2.5.0/forwardable/impl.rb:6 - <compiled>: syntax error, unexpected end-of-input ().port= ^ Exception LoadError' at /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59 - cannot load such file -- idn
Exception LoadError' at /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:137 - cannot load such file -- idn Exception LoadError' at /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59 - cannot load such file -- idn
Exception LoadError' at /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:137 - cannot load such file -- idn Application client/secret? Authentication Token? true Exception LoadError' at /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59 - cannot load such file -- yajl
Exception LoadError' at /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:137 - cannot load such file -- yajl Exception LoadError' at /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59 - cannot load such file -- multi_json
Exception `LoadError' at /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:137 - cannot load such file -- multi_json
Using Ext extension for JSON.
I, [2020-03-13T14:22:10.797362 #5942] INFO -- request: GET https://api.github.com/user
I, [2020-03-13T14:22:10.797645 #5942] INFO -- request: Accept: "application/vnd.github.v3+json"
User-Agent: "Octokit Ruby Gem 4.17.0"
Content-Type: "application/json"
Authorization: "token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
I, [2020-03-13T14:22:11.358629 #5942] INFO -- response: Status 200
I, [2020-03-13T14:22:11.359097 #5942] INFO -- response: date: "Fri, 13 Mar 2020 13:22:09 GMT"
content-type: "application/json; charset=utf-8"
transfer-encoding: "chunked"
connection: "close"
server: "GitHub.com"
status: "200 OK"
x-ratelimit-limit: "5000"
x-ratelimit-remaining: "4994"
x-ratelimit-reset: "1584107606"
cache-control: "private, max-age=60, s-maxage=60"
vary: "Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept, X-Requested-With"
etag: "W/"1ba9f7f769f4ec84d8167b574fc80a6e""
last-modified: "Tue, 10 Mar 2020 10:52:49 GMT"
x-oauth-scopes: "admin:enterprise, admin:org, admin:public_key, delete_repo, gist, notifications, read:packages, repo, user, write:packages"
x-accepted-oauth-scopes: ""
x-github-media-type: "github.v3; format=json"
access-control-expose-headers: "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset"
access-control-allow-origin: ""
strict-transport-security: "max-age=31536000; includeSubdomains; preload"
x-frame-options: "deny"
x-content-type-options: "nosniff"
x-xss-protection: "1; mode=block"
referrer-policy: "origin-when-cross-origin, strict-origin-when-cross-origin"
content-security-policy: "default-src 'none'"
x-github-request-id: "3F28:6581:2D6FCE8:3575709:5E6B8900"
Scopes: admin:enterprise,admin:org,admin:public_key,delete_repo,gist,notifications,read:packages,repo,user,write:packages
I, [2020-03-13T14:22:11.373147 #5942] INFO -- request: GET https://api.github.com/rate_limit
I, [2020-03-13T14:22:11.373349 #5942] INFO -- request: Accept: "application/vnd.github.v3+json"
User-Agent: "Octokit Ruby Gem 4.17.0"
Content-Type: "application/json"
Authorization: "token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
I, [2020-03-13T14:22:11.860253 #5942] INFO -- response: Status 200
I, [2020-03-13T14:22:11.860849 #5942] INFO -- response: date: "Fri, 13 Mar 2020 13:22:09 GMT"
content-type: "application/json; charset=utf-8"
transfer-encoding: "chunked"
connection: "close"
server: "GitHub.com"
status: "200 OK"
x-ratelimit-limit: "5000"
x-ratelimit-remaining: "4994"
x-ratelimit-reset: "1584107606"
cache-control: "no-cache"
x-oauth-scopes: "admin:enterprise, admin:org, admin:public_key, delete_repo, gist, notifications, read:packages, repo, user, write:packages"
x-accepted-oauth-scopes: ""
x-github-media-type: "github.v3; format=json"
access-control-expose-headers: "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset"
access-control-allow-origin: "
"
strict-transport-security: "max-age=31536000; includeSubdomains; preload"
x-frame-options: "deny"
x-content-type-options: "nosniff"
x-xss-protection: "1; mode=block"
referrer-policy: "origin-when-cross-origin, strict-origin-when-cross-origin"
content-security-policy: "default-src 'none'"
vary: "Accept-Encoding, Accept, X-Requested-With"
x-github-request-id: "DD47:2AC70:192F26E:1D87A8C:5E6B8901"
Rate limit: 4994/5000

apiHost not working for certain URLs

// Determine the API URL for this GitHub Enterprise server
const hostnames = location.hostname.split('.')
const apiHost = location.protocol + '//' + hostnames[hostnames.length - 2] + '.' + hostnames[hostnames.length - 1]

With an URL in the form of https://github.example.co.uk, we get

// hostnames[hostnames.length - 2] >> 'co'
// hostnames[hostnames.length - 1] >> 'uk'
// --> apiHost -> https://co.uk

Expected:

// --> apiHost -> https://github.example.co.uk

block_file_extensions.sh can be circumvented with fork + PR

The block_file_extensions.sh pre-receive-hook can be circumvented by:

  1. Fork the repository
  2. Add a file with the blocked exension
  3. Submit a pull request
  4. Merge pull request

We've done a little research and suspect that this is due to the:

excludeExisting="--not --all"

I guess we could mitigate, e.g. by adding block_self_merge_prs.sh, but this could still be circumvented if 2 users with write privileges colluded.

Any thoughts?

set and get status improvements

  • let users pass args to these commands instead of requiring them to type JSON, e.g.
    ./set-status success https://myciserver.org "my build worked!" "my context"
  • offer a -h or --help option for all or none of the commands
  • if it prints to screen, make it pretty (e.g. get-status currently dumps unformatted text that can be a bit indecipherable

block_confidentials.sh -hook script in git is not working properly even after reverted the changes

I used below pre-receive script for blocking the developers from committing the secrets insides the files.

followed the below steps to set up this in GitHub Enterprise Appliance.

  1. created a repo in github, cloned to local desktop. saved the copied script (https://github.com/github/platform-samples/blob/master/pre-receive-hooks/block_confidentials.sh ) from the site as .sh file and committed and pushed.

  2. in GitHub as site admin , created a hook from admincenter and pointed to previously created hookscriptone.

and after that i tested a scenario wit creating a new repo and adding a example.conf file to this.

  1. When i did first commit with the simple content (without any secrets), its allowed me to commit .

  2. in second scenario, i committed with a keyword "CONFIDENTIAL" in it, but it blocked as expected.

  3. so for confirming the hooks functionality, i removed the "Confidential" word and tried to commit back.. but its still not allowing me to commit.

Any helps pls...

Debuging error

Am having this error each time i try to run the emulator for my project...................................
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.

Add an example of iterating through pull request changed files in ruby.

I currently got this much done on it myself, however with not knowing ruby much at all I am not sure if I coded it all right. The code lies at https://github.com/Elskom/CI/blob/master/CI.rb. Yes it is formatted like the building a CI server example but with pull request label check for "skip news", and a "Misc/NEWS" entry check for if a new file was added there. I am not sure how I can filter it though to where that check only works with new entry files, not modified or deleted ones unless all of them merged to a single file (like right before a release). I would also love to be able to have my CI read comments from repo /org admins though for things like "I approve this" where the CI then approves the changes and then waits for "merge squashed/rebased/commit". I personally think it would be great to have an example like that tbh. And yes, feel free to use the code I got so far on an example, I don’t mind if you guys even linked to it too. Also I thought those octocat stuff was some sort of photoshopped thing. πŸ€”

Issues

~/Developer/platform-samples/hooks/ruby/configuring-your-server $ ruby server.rb
== Sinatra/1.4.4 has taken the stage on 4567 for development with backup from Thin

Thin web server (v1.5.1 codename Straight Razor)
Maximum connections set to 1024
Listening on localhost:4567, CTRL+C to stop
I got some JSON: {"action"=>"opened", "issue"=>{"url"=>"..

Script to add unassigned users to an org

It would be useful to have a script that searches a GitHub Enterprise instance for users that aren't part of an Organization, then batch invites those users to the Org.

Delivering deployments tutorial returns 409 on create deployment

Hi! I was following the tutorial on delivering deployments with the Github API, but after copying and pasting the code EXACTLY, I receive a 409 merge conflict error. I have provided the files and error code below.

This happens even when the following options are passed:

{ auto_merge: false }

I greatly appreciate your time. Perhaps I am just overlooking something... πŸ˜„

deploy.rb

require 'sinatra/base'
require 'json'
require 'octokit'

class DeploymentTutorial < Sinatra::Base

  ACCESS_TOKEN = ENV['MY_PERSONAL_TOKEN']

  before do
    @client ||= Octokit::Client.new(:access_token => ACCESS_TOKEN)
  end

  post '/event_handler' do
    @payload = JSON.parse(params[:payload])

    case request.env['HTTP_X_GITHUB_EVENT']
    when "pull_request"
      if @payload["action"] == "closed" && @payload["pull_request"]["merged"]
        start_deployment(@payload["pull_request"])
      end
    when "deployment"
      process_deployment
    when "deployment_status"
      update_deployment_status
    end
  end

  helpers do
    def start_deployment(pull_request)
      user = pull_request['user']['login']
      payload = JSON.generate(:environment => 'production', :deploy_user => user)
      @client.create_deployment(pull_request['head']['repo']['full_name'], pull_request['head']['sha'], {:payload => payload, :description => "Deploying my sweet branch"})
    end

    def process_deployment
      payload = JSON.parse(@payload['payload'])
      # you can send this information to your chat room, monitor, pager, e.t.c.
      puts "Processing '#{@payload['description']}' for #{payload['deploy_user']} to #{payload['environment']}"
      sleep 2 # simulate work
      @client.create_deployment_status("repos/#{@payload['repository']['full_name']}/deployments/#{@payload['id']}", 'pending')
      sleep 2 # simulate work
      @client.create_deployment_status("repos/#{@payload['repository']['full_name']}/deployments/#{@payload['id']}", 'success')
    end

    def update_deployment_status
      puts "Deployment status for #{@payload['id']} is #{@payload['state']}"
    end
  end
end

Gemfile

source "http://rubygems.org"

gem "json",        "~> 1.8"
gem 'sinatra',     '~> 1.3.5'
gem "shotgun"
gem "octokit",     '~> 3.0'

Gemfile.lock

GEM
  remote: http://rubygems.org/
  specs:
    addressable (2.3.8)
    faraday (0.9.2)
      multipart-post (>= 1.2, < 3)
    json (1.8.3)
    multipart-post (2.0.0)
    octokit (3.8.0)
      sawyer (~> 0.6.0, >= 0.5.3)
    rack (1.6.4)
    rack-protection (1.5.3)
      rack
    sawyer (0.6.0)
      addressable (~> 2.3.5)
      faraday (~> 0.8, < 0.10)
    shotgun (0.9.1)
      rack (>= 1.0)
    sinatra (1.3.6)
      rack (~> 1.4)
      rack-protection (~> 1.3)
      tilt (~> 1.3, >= 1.3.3)
    tilt (1.4.1)

PLATFORMS
  ruby

DEPENDENCIES
  json (~> 1.8)
  octokit (~> 3.0)
  shotgun
  sinatra (~> 1.3.5)

BUNDLED WITH
   1.12.5

config.ru

require "./deploy"
run DeploymentTutorial

Sinatra Errors

192.30.252.40 - - [28/Jun/2016:19:44:33 -0700] "POST /event_handler HTTP/1.1" 200 - 0.0174
Octokit::Conflict - POST https://api.github.com/repos/thisiserik/yo/deployments: 409 - Conflict merging master into f8e965b31d494d6b08cdd9fb392e00d80580ec45. // See: https://developer.github.com/v3/repos/deployments/#create-a-deployment:
    /usr/local/rvm/gems/ruby-2.2.0/gems/octokit-3.8.0/lib/octokit/response/raise_error.rb:16:in `on_complete'
    /usr/local/rvm/gems/ruby-2.2.0/gems/faraday-0.9.2/lib/faraday/response.rb:9:in `block in call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/faraday-0.9.2/lib/faraday/response.rb:57:in `on_complete'
    /usr/local/rvm/gems/ruby-2.2.0/gems/faraday-0.9.2/lib/faraday/response.rb:8:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/faraday-0.9.2/lib/faraday/rack_builder.rb:139:in `build_response'
    /usr/local/rvm/gems/ruby-2.2.0/gems/faraday-0.9.2/lib/faraday/connection.rb:377:in `run_request'
    /usr/local/rvm/gems/ruby-2.2.0/gems/faraday-0.9.2/lib/faraday/connection.rb:177:in `post'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sawyer-0.6.0/lib/sawyer/agent.rb:94:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/octokit-3.8.0/lib/octokit/client.rb:339:in `request'
    /usr/local/rvm/gems/ruby-2.2.0/gems/octokit-3.8.0/lib/octokit/client.rb:144:in `post'
    /usr/local/rvm/gems/ruby-2.2.0/gems/octokit-3.8.0/lib/octokit/client/deployments.rb:33:in `create_deployment'
    /Users/Erik/Desktop/deploy/deploy.rb:32:in `start_deployment'
    /Users/Erik/Desktop/deploy/deploy.rb:19:in `block in <class:DeploymentTutorial>'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:1293:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:1293:in `block in compile!'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:860:in `[]'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:860:in `block (3 levels) in route!'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:876:in `route_eval'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:860:in `block (2 levels) in route!'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:897:in `block in process_route'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:895:in `catch'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:895:in `process_route'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:859:in `block in route!'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:858:in `each'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:858:in `route!'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:963:in `block in dispatch!'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:946:in `block in invoke'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:946:in `catch'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:946:in `invoke'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:960:in `dispatch!'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:794:in `block in call!'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:946:in `block in invoke'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:946:in `catch'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:946:in `invoke'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:794:in `call!'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:780:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/rack-1.6.4/lib/rack/nulllogger.rb:9:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/rack-1.6.4/lib/rack/head.rb:13:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/showexceptions.rb:21:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:124:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:1417:in `block in call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:1499:in `synchronize'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:1417:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/rack-1.6.4/lib/rack/tempfile_reaper.rb:15:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/rack-1.6.4/lib/rack/lint.rb:49:in `_call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/rack-1.6.4/lib/rack/lint.rb:37:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/rack-1.6.4/lib/rack/showexceptions.rb:24:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/rack-1.6.4/lib/rack/commonlogger.rb:33:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:161:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/rack-1.6.4/lib/rack/chunked.rb:54:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/rack-1.6.4/lib/rack/content_length.rb:15:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/rack-1.6.4/lib/rack/handler/webrick.rb:88:in `service'
    /usr/local/rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
    /usr/local/rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
    /usr/local/rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
NoMethodError: undefined method `join' for #<String:0x007ff624205180>
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/showexceptions.rb:37:in `rescue in call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/showexceptions.rb:21:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:124:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:1417:in `block in call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:1499:in `synchronize'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:1417:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/rack-1.6.4/lib/rack/tempfile_reaper.rb:15:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/rack-1.6.4/lib/rack/lint.rb:49:in `_call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/rack-1.6.4/lib/rack/lint.rb:37:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/rack-1.6.4/lib/rack/showexceptions.rb:24:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/rack-1.6.4/lib/rack/commonlogger.rb:33:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/sinatra-1.3.6/lib/sinatra/base.rb:161:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/rack-1.6.4/lib/rack/chunked.rb:54:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/rack-1.6.4/lib/rack/content_length.rb:15:in `call'
    /usr/local/rvm/gems/ruby-2.2.0/gems/rack-1.6.4/lib/rack/handler/webrick.rb:88:in `service'
    /usr/local/rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
    /usr/local/rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
    /usr/local/rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
192.30.252.45 - - [28/Jun/2016:19:44:36 -0700] "POST /event_handler HTTP/1.1" 500 162525 0.4771

pre-receive hook doesn't run if repository doesn't exist

I've setup a global pre-receive hook on my own server (Ubunto 16.04.2 with Git 2.16.2), which works fine with existing repositories. However, if the repository does not exist, the script does not run and I get a client side error instead.
Is there a server side hook I can use that will run when someone tries to push to a repo that doesn't exist? Or, how else can I catch the event?

Script to add all organization repos to a team

It would be useful to have a script that:

  1. Gets a list of organization-owned repos
  2. Adds all of those repos to a specified team

Alternatively, it might be better to allow the user to specify a list of repos instead, passing it to the command.

Business metrics export script

Could we create a script to export useful business metrics (Issues/PRs opened & closed, deploys, etc.) from a GitHub org or a complete GitHub Enterprise instance?

Not able to use .env file for basics-of-authentication project

@gjtorikian @nathos @jasonrudolph

Hello guys, πŸ˜„

I'm a newbie in this project and I'm not able to use an .env file like:

GH_BASIC_CLIENT_ID=1234567890
GH_BASIC_SECRET_ID=0987654321

for the basics-of-authentication project!

After using bundle install and ruby server.rb or ruby advanced_server.rb the link for login in http://localhost:4567/ looks like:

https://github.com/login/oauth/authorize?scope=user:email&client_id=

instead of

https://github.com/login/oauth/authorize?scope=user:email&client_id=12345667890

I already read the tutorial on GitHub Developer platform.

Where is the error and what should I do?

Yours,
Suriyaa Kudo :octocat:

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.