{"id":15625487,"url":"https://github.com/xuanxu/issue","last_synced_at":"2025-03-29T17:15:04.518Z","repository":{"id":56878118,"uuid":"381322972","full_name":"xuanxu/issue","owner":"xuanxu","description":"Ruby gem to parse issue events coming from webhook payloads","archived":false,"fork":false,"pushed_at":"2024-03-17T20:49:11.000Z","size":61,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-03-17T21:54:42.885Z","etag":null,"topics":["ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xuanxu.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-06-29T10:17:39.000Z","updated_at":"2024-04-15T12:06:44.230Z","dependencies_parsed_at":"2022-08-20T11:40:35.920Z","dependency_job_id":"513f4f63-5139-4adb-99ce-e417a4bed322","html_url":"https://github.com/xuanxu/issue","commit_stats":{"total_commits":42,"total_committers":1,"mean_commits":42.0,"dds":0.0,"last_synced_commit":"9857f2e0b9eab5e979c29b9d70638544ce9adcda"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xuanxu%2Fissue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xuanxu%2Fissue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xuanxu%2Fissue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xuanxu%2Fissue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xuanxu","download_url":"https://codeload.github.com/xuanxu/issue/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246215828,"owners_count":20741894,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ruby"],"created_at":"2024-10-03T10:01:46.503Z","updated_at":"2025-03-29T17:15:04.470Z","avatar_url":"https://github.com/xuanxu.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Issue\n[![Gem Version](https://badge.fury.io/rb/issue.svg)](https://badge.fury.io/rb/issue)\n[![Tests](https://github.com/xuanxu/issue/actions/workflows/tests.yml/badge.svg)](https://github.com/xuanxu/issue/actions/workflows/tests.yml)\n\nIssue is a small library dedicated to parse requests coming from GitHub webhooks triggered by `issues`, `issue_comment` and `pull_request` events.\n\n## Getting started\n\nDepending on your project you may:\n\nInstall the gem:\n```bash\n$ gem install issue\n```\nor add it to your Gemfile:\n```ruby\ngem 'issue'\n```\n\nRequire the gem with:\n```ruby\nrequire 'issue'\n```\n\n## Usage\n\nThe `Issue::Webhook` is used to declare and parse a GitHub webhook. At initialization it accepts a hash of configuration settings:\n\n- **secret_token**: The GitHub secret access token for authorization\n- **origin**: The repository to accept payloads from. If nil any origin will be accepted. If not nil any request from a different repository will be ignored\n- **discard_sender**: The GitHub handle of a user whose events will be ignored. Usually the organization bot. If nil no user will be ignored. To ignore only specific events use a Hash where keys are usernames and values are arrays of events to ignore for that username.\n- **accept_events**: An Array of GitHub event types to accept. If nil all events will be accepted.\n\nOnce it is initialized a request can be parsed passing it to the **`parse_request`** method. After verifying the request signature and checking for the configurated conditions the `parse_request` method returns a [Payload, Error] pair, where the error is nil if nothing failed, and the payload is nil if an error ocurred.\n\n```ruby\nwebhook = Issue::Webhook.new(secret_token: ENV[\"GH_SECRET\"],\n                             origin: \"myorg/reponame\",\n                             discard_sender: \"myorg_bot\"\n                             accept_events: [\"issues\", \"issue_comment\"])\n\npayload, error = webhook.parse_request(request)\n\nif webhook.errored?\n  head error.status, msg: error.message\nelse\n  # do_something_based_on_the(payload)\n  head 200\nend\n\n```\n\n### The Payload object\n\nThe `Issue::Payload` object includes all the parsed information coming from the webhook request. It has the following instance methods:\n\n- **context**: This method returns a OpenStruct with the following structure:\n```ruby\n  action:             # the webhook action,\n  event:              # the GitHub event coming in the HTTP_X_GITHUB_EVENT request header\n  issue_id:           # the issue number\n  issue_title:        # issue title,\n  issue_body:         # body of the issue\n  issue_author:       # author of the issue\n  issue_labels:       # labels of the issue\n  repo:               # the full name of the origin repository\n  sender:             # the login of the user triggering the webhook action\n  event_action:       # a string: \"event.action\"\n  comment_id:         # id of the comment\n  comment_body:       # body of the comment\n  comment_created_at: # created_at value of the comment\n  comment_url:        # the html url for the comment\n  raw_payload:        # a hash with the complete parsed JSON request\n```\n- **accesor methods** for every key in the context\n- **opened?**: `true` if the action is `opened` or `reopened`\n- **closed?**: `true` if the action is `closed`\n- **commented?**: `true` if the action is `created`\n- **edited?**: `true` if the action is `edited`\n- **locked?**: `true` if the action is `locked`\n- **unlocked?**: `true` if the action is `unlocked`\n- **pinned?**: `true` if the action is `pinned` or `unpinned`\n- **assigned?**: `true` if the action is `assigned` or `unassigned`\n- **labeled?**: `true` if the action is `labeled` or `unlabeled`\n\n## License\n\nReleased under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxuanxu%2Fissue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxuanxu%2Fissue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxuanxu%2Fissue/lists"}