From 5eba8570ec2e76c412fed3095878baa439b60341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilien=20Pressens=C3=A9?= Date: Sun, 16 Nov 2025 10:31:42 +0100 Subject: [PATCH] wip --- .../webhooks/github_events_controller.rb | 34 ++ app/models/github_event.rb | 11 + app/services/github_events/create_service.rb | 66 +++ config/credentials.yml.enc | 2 +- config/routes.rb | 2 + .../20250403123232_create_github_event.rb | 13 + db/schema.rb | 13 +- spec/factories/github_events.rb | 460 ++++++++++++++++++ spec/models/github_event_spec.rb | 9 + .../github_events/create_service_spec.rb | 34 ++ 10 files changed, 642 insertions(+), 2 deletions(-) create mode 100644 app/controllers/webhooks/github_events_controller.rb create mode 100644 app/models/github_event.rb create mode 100644 app/services/github_events/create_service.rb create mode 100644 db/migrate/20250403123232_create_github_event.rb create mode 100644 spec/factories/github_events.rb create mode 100644 spec/models/github_event_spec.rb create mode 100644 spec/services/github_events/create_service_spec.rb diff --git a/app/controllers/webhooks/github_events_controller.rb b/app/controllers/webhooks/github_events_controller.rb new file mode 100644 index 00000000..a7cd8bad --- /dev/null +++ b/app/controllers/webhooks/github_events_controller.rb @@ -0,0 +1,34 @@ +class Webhooks::GithubEventsController < ApplicationController + skip_before_action :verify_authenticity_token + skip_before_action :authenticate + skip_before_action :require_authentication + + before_action :validate_signature + + def create + github_event = GithubEvent.create!( + event: request.headers["X-GitHub-Event"], + payload: request.request_parameters.except("repository", "organization") + # contribution: Contribution.find_by!(github_resource_url: payload["pull_request"]["url"]) + ) + + GithubEvents::CreateService.new(github_event:).call + + head :ok + end + + private + + def validate_signature + signature = request.headers["X-Hub-Signature-256"] + head :unauthorized and return unless signature&.start_with?("sha256=") + + secret = Rails.application.credentials.github.webhook_secret + expected = "sha256=" + OpenSSL::HMAC.hexdigest("sha256", secret, request.raw_post) + + unless ActiveSupport::SecurityUtils.secure_compare(expected, signature) + Rails.logger.warn "Invalid GitHub webhook signature" + head :unauthorized + end + end +end diff --git a/app/models/github_event.rb b/app/models/github_event.rb new file mode 100644 index 00000000..f6184735 --- /dev/null +++ b/app/models/github_event.rb @@ -0,0 +1,11 @@ +class GithubEvent < ApplicationRecord + belongs_to :contribution, optional: true + # validates :event, presence: true + # validates :payload, presence: true + + enum :status, { + pending: "pending", + processed: "processed", + ignored: "ignored" + } +end diff --git a/app/services/github_events/create_service.rb b/app/services/github_events/create_service.rb new file mode 100644 index 00000000..c5904e0e --- /dev/null +++ b/app/services/github_events/create_service.rb @@ -0,0 +1,66 @@ +module GithubEvents + class CreateService + attr_reader :github_event + + def initialize(github_event:) + @github_event = github_event + end + + def call + case github_event.event + when "pull_request" # I should probably not use this one + handle_pull_request_event + when "pull_request_review" + handle_pull_request_review_event + else + ignore_event! + end + end + + private + + def handle_pull_request_event + ignore_event! unless github_action == "closed" + + return if contribution.status == "validée" + + contribution.update!(status: "rejetée") + end + + def handle_pull_request_review_event + case github_action + when "submitted" + case github_event.payload["review"]["state"] + when "changes_requested" + ActiveRecord::Base.transaction do + contribution.update!(status: "modifications demandées") + github_event.update!(contribution:, status: "processed") + end + when "approved" # actually it might be better to do so at the merge event + ActiveRecord::Base.transaction do + contribution.update!(status: "validée") + Osbl.create!(contribution.osbl_data) + github_event.update!(contribution:, status: "processed") + end + else + ignore_event! + end + else + ignore_event! + end + end + + def contribution + @contribution ||= Contribution.find_by!(github_resource_url: github_event.payload["pull_request"]["html_url"]) + end + + def ignore_event! + github_event.update!(status: "ignored") + Rails.logger.info "GitHub event ignored: #{github_event.id}" + end + + def github_action + github_event.payload["action"] + end + end +end diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc index b4d84422..ac8230ae 100644 --- a/config/credentials.yml.enc +++ b/config/credentials.yml.enc @@ -1 +1 @@ -1ac0XCWb7MwmmrVOD+aw7yjIuxj5bMXRFrukNTHK7ds21vyaANghbmjcIwUrL2nz81lNGVR6uUVLw9E/ahRneKepCVxW0psXLqQlIzsQEcuoRuiCLNkVE/prxN2VQ0JPk9rMy9vRrf+f+4y/TapKp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m9eD/xHFomgUWTVelUMO9MBBb5eH+if/G5wR8gR/sJHxYyZQltSRG+Por8Z9JuB4CK5pWMYLBr5DHZ5oWhUuboydLSfB67XIZc349PxoGJCO4uiRV/UqhO3m0GKCSYMTBD4cn8Es6uEu/Gp3otu1h65FeF00i8O3eO8y5KH3kCGKYSg2NoDfhI34RCD3Xx5iHsCs82WKZuIVKaIBQ0LfvYCwK8jKa6EZ7BMPUqkvNbE+tHA7p5R314749YLmRIL0RndALj8Pei8GK9ifLHzN4L760BPvPZooUb+wlJaBlCmzJoN6e53tn9w++cNEiQzWGWzIirSOURYCdyQi+tjg5gvdfJXArg6C+hKcWwGLrv0hi1OvP6TiTr6Crx3cZKxIsAcAXY3qyvh7I7mMnBdA4bygZm/6CjuL0Vv+X+qPTj5UebpIc9xGYU9CGFEjiPsoae9vRTkf8gXXsxGpxVlHNyeAxf+X9fTgFzbNvt+kQO9yT0nF3vqPSPcJjfNc7tnhHJXDW4daGyjCRgnu0XVIufcxnwjCbUzG038wrMd7U/MXLt0yAhZ8gug5ivhQgrqzbiv4U0TEPypkdAvUZd9yUwhksvSA3bkYpPQpW02WTQwHSIQ2iLlSlsZ84Cta4xuG882WNd5UIA0KJam8a7IcSeqpbrhXYBR7QZIXJ+ymMjDT7WOB7FCjKABGnLZP4R7h3lHD2rJi9Q9/ltRxQK95iiT1ZDKVqf5o8wTrjgwwizgpTUNMlCPi3uthdRAmrPirR/O26DrNIPDgmdLpC2YIgEo2uISewHtZuy3gkXGRR5flQKG3lzhcOxkE9AvVLqYsSP6RNlmOjbnZGqvtJoaum/baLOxmERo+iEvRB2rm+JV9fPH0+ZPpdjYDma8bujRdj1Kky0n4Fgg3xzw/UQnxhtghud2Y9wj71FSTcMEDWfQhz5asahtbu7Trit7jAXVeAWBuCEmibd2JT1HCeFGsF4ZYYPThfF5rENr--FXzmVzKeSOHPa3D5--08W/g+J4EtERL68rHU6cqg== \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 0e639389..aef2a2d4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -26,6 +26,8 @@ get "mes-contributions/:id", to: "users/contributions#show", as: :my_contribution get "mes-contributions/:id/modifier", to: "users/contributions#edit", as: :edit_my_contribution + resources :github_events, only: [:create], module: :webhooks + resources :contributions, only: [:show, :edit, :update] resources :osbl_imports, only: [:create, :show] diff --git a/db/migrate/20250403123232_create_github_event.rb b/db/migrate/20250403123232_create_github_event.rb new file mode 100644 index 00000000..6ebd29cb --- /dev/null +++ b/db/migrate/20250403123232_create_github_event.rb @@ -0,0 +1,13 @@ +class CreateGithubEvent < ActiveRecord::Migration[8.0] + def change + create_table :github_events do |t| + t.string :event, null: false + t.json :payload, null: false + t.string :status, null: false, default: "pending" + + t.references :contribution, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 8730a73b..1f8a6f7d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2025_02_28_122447) do +ActiveRecord::Schema[8.0].define(version: 2025_04_03_123232) do create_table "accounts", force: :cascade do |t| end @@ -119,6 +119,16 @@ t.check_constraint "year >= 1000", name: "year_as_4_digits" end + create_table "github_events", force: :cascade do |t| + t.string "event", null: false + t.json "payload", null: false + t.string "status", default: "pending", null: false + t.integer "contribution_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["contribution_id"], name: "index_github_events_on_contribution_id" + end + create_table "osbl_annual_finances", force: :cascade do |t| t.integer "year", null: false t.decimal "treasury", precision: 15, scale: 2 @@ -301,6 +311,7 @@ add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" add_foreign_key "contributions", "users" add_foreign_key "document_attachments", "documents", on_delete: :cascade + add_foreign_key "github_events", "contributions" add_foreign_key "osbl_annual_finances", "osbls", on_delete: :cascade add_foreign_key "osbl_fund_allocations", "osbl_annual_finances", column: "annual_finance_id", on_delete: :cascade add_foreign_key "osbl_fund_sources", "osbl_annual_finances", column: "annual_finance_id", on_delete: :cascade diff --git a/spec/factories/github_events.rb b/spec/factories/github_events.rb new file mode 100644 index 00000000..06402f35 --- /dev/null +++ b/spec/factories/github_events.rb @@ -0,0 +1,460 @@ +FactoryBot.define do + factory :github_event do + event { "pull_request_review" } + status { "pending" } + payload do + { + "action" => "submitted", + "review" => { + "id" => 2739958290, + "node_id" => "PRR_kwDOOEHVCs6jUHIS", + "user" => + { + "login" => "mpressen", + "id" => 16125283, + "node_id" => "MDQ6VXNlcjE2MTI1Mjgz", + "avatar_url" => "https://avatars.githubusercontent.com/u/16125283?v=4", + "gravatar_id" => "", + "url" => "https://api.github.com/users/mpressen", + "html_url" => "https://github.com/mpressen", + "followers_url" => "https://api.github.com/users/mpressen/followers", + "following_url" => "https://api.github.com/users/mpressen/following{/other_user}", + "gists_url" => "https://api.github.com/users/mpressen/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/mpressen/starred{/owner}{/repo}", + "subscriptions_url" => "https://api.github.com/users/mpressen/subscriptions", + "organizations_url" => "https://api.github.com/users/mpressen/orgs", + "repos_url" => "https://api.github.com/users/mpressen/repos", + "events_url" => "https://api.github.com/users/mpressen/events{/privacy}", + "received_events_url" => "https://api.github.com/users/mpressen/received_events", + "type" => "User", + "user_view_type" => "public", + "site_admin" => false + }, + "body" => "d'où proviennent ces infos ?", + "commit_id" => "d82bb33be655ac11075b8f49346395fdecf69586", + "submitted_at" => "2025-04-03T13:56:50Z", + "state" => "changes_requested", + "html_url" => "https://github.com/Benefactorum/contributions/pull/31#pullrequestreview-2739958290", + "pull_request_url" => "https://api.github.com/repos/Benefactorum/contributions/pulls/31", + "author_association" => "CONTRIBUTOR", + "_links" => + { + "html" => { + "href" => "https://github.com/Benefactorum/contributions/pull/31#pullrequestreview-2739958290" + }, + "pull_request" => { + "href" => "https://api.github.com/repos/Benefactorum/contributions/pulls/31" + } + } + }, + "pull_request" => { + "url" => "https://api.github.com/repos/Benefactorum/contributions/pulls/31", + "id" => 2437049304, + "node_id" => "PR_kwDOOEHVCs6RQmvY", + "html_url" => "https://github.com/Benefactorum/contributions/pull/31", + "diff_url" => "https://github.com/Benefactorum/contributions/pull/31.diff", + "patch_url" => "https://github.com/Benefactorum/contributions/pull/31.patch", + "issue_url" => "https://api.github.com/repos/Benefactorum/contributions/issues/31", + "number" => 31, + "state" => "open", + "locked" => false, + "title" => "Création de l'OSBL: test creation d'asso", + "user" => + { + "login" => "benefactorum-contributions[bot]", + "id" => 202140456, + "node_id" => "BOT_kgDODAxrKA", + "avatar_url" => "https://avatars.githubusercontent.com/in/1168620?v=4", + "gravatar_id" => "", + "url" => "https://api.github.com/users/benefactorum-contributions%5Bbot%5D", + "html_url" => "https://github.com/apps/benefactorum-contributions", + "followers_url" => "https://api.github.com/users/benefactorum-contributions%5Bbot%5D/followers", + "following_url" => "https://api.github.com/users/benefactorum-contributions%5Bbot%5D/following{/other_user}", + "gists_url" => "https://api.github.com/users/benefactorum-contributions%5Bbot%5D/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/benefactorum-contributions%5Bbot%5D/starred{/owner}{/repo}", + "subscriptions_url" => "https://api.github.com/users/benefactorum-contributions%5Bbot%5D/subscriptions", + "organizations_url" => "https://api.github.com/users/benefactorum-contributions%5Bbot%5D/orgs", + "repos_url" => "https://api.github.com/users/benefactorum-contributions%5Bbot%5D/repos", + "events_url" => "https://api.github.com/users/benefactorum-contributions%5Bbot%5D/events{/privacy}", + "received_events_url" => "https://api.github.com/users/benefactorum-contributions%5Bbot%5D/received_events", + "type" => "Bot", + "user_view_type" => "public", + "site_admin" => false + }, + "body" => + "### Description de la contribution\n\nCeci est un test !\n\n### Fichiers joints\n\n- [profile-pic.jpeg](http://localhost:3000/rails/active_storage/blobs/redirect/eyJfcmF +pbHMiOnsiZGF0YSI6MjMsInB1ciI6ImJsb2JfaWQifX0=--696f6f7c81df487bc93a6d2b3f1a15110c855b1e/profile-pic.jpeg)\n\n\n### Actions via Benefactorum\n\n[Voir + ](http: //localhost:3000/co +ntributions/17) - [Modifier + ](http: //localhost:3000/contributions/17/edit)", + "created_at" => "2025-04-03T13:26:59Z", + "updated_at" => "2025-04-03T13:56:50Z", + "closed_at" => nil, + "merged_at" => nil, + "merge_commit_sha" => "fb6a8bcb6960c17b24160685018d8b2f17f526c2", + "assignee" => nil, + "assignees" => [], + "requested_reviewers" => [], + "requested_teams" => [], + "labels" => [], + "milestone" => nil, + "draft" => false, + "commits_url" => "https://api.github.com/repos/Benefactorum/contributions/pulls/31/commits", + "review_comments_url" => "https://api.github.com/repos/Benefactorum/contributions/pulls/31/comments", + "review_comment_url" => "https://api.github.com/repos/Benefactorum/contributions/pulls/comments{/number}", + "comments_url" => "https://api.github.com/repos/Benefactorum/contributions/issues/31/comments", + "statuses_url" => "https://api.github.com/repos/Benefactorum/contributions/statuses/d82bb33be655ac11075b8f49346395fdecf69586", + "head" => + { + "label" => "Benefactorum:osbl_creation/2025-04-03/17/test-creation-d-asso", + "ref" => "osbl_creation/2025-04-03/17/test-creation-d-asso", + "sha" => "d82bb33be655ac11075b8f49346395fdecf69586", + "user" => + { + "login" => "Benefactorum", + "id" => 143507729, + "node_id" => "O_kgDOCI3BEQ", + "avatar_url" => "https://avatars.githubusercontent.com/u/143507729?v=4", + "gravatar_id" => "", + "url" => "https://api.github.com/users/Benefactorum", + "html_url" => "https://github.com/Benefactorum", + "followers_url" => "https://api.github.com/users/Benefactorum/followers", + "following_url" => "https://api.github.com/users/Benefactorum/following{/other_user}", + "gists_url" => "https://api.github.com/users/Benefactorum/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/Benefactorum/starred{/owner}{/repo}", + "subscriptions_url" => "https://api.github.com/users/Benefactorum/subscriptions", + "organizations_url" => "https://api.github.com/users/Benefactorum/orgs", + "repos_url" => "https://api.github.com/users/Benefactorum/repos", + "events_url" => "https://api.github.com/users/Benefactorum/events{/privacy}", + "received_events_url" => "https://api.github.com/users/Benefactorum/received_events", + "type" => "Organization", + "user_view_type" => "public", + "site_admin" => false + }, + "repo" => + { + "id" => 943838474, + "node_id" => "R_kgDOOEHVCg", + "name" => "contributions", + "full_name" => "Benefactorum/contributions", + "private" => false, + "owner" => + { + "login" => "Benefactorum", + "id" => 143507729, + "node_id" => "O_kgDOCI3BEQ", + "avatar_url" => "https://avatars.githubusercontent.com/u/143507729?v=4", + "gravatar_id" => "", + "url" => "https://api.github.com/users/Benefactorum", + "html_url" => "https://github.com/Benefactorum", + "followers_url" => "https://api.github.com/users/Benefactorum/followers", + "following_url" => "https://api.github.com/users/Benefactorum/following{/other_user}", + "gists_url" => "https://api.github.com/users/Benefactorum/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/Benefactorum/starred{/owner}{/repo}", + "subscriptions_url" => "https://api.github.com/users/Benefactorum/subscriptions", + "organizations_url" => "https://api.github.com/users/Benefactorum/orgs", + "repos_url" => "https://api.github.com/users/Benefactorum/repos", + "events_url" => "https://api.github.com/users/Benefactorum/events{/privacy}", + "received_events_url" => "https://api.github.com/users/Benefactorum/received_events", + "type" => "Organization", + "user_view_type" => "public", + "site_admin" => false + }, + "html_url" => "https://github.com/Benefactorum/contributions", + "description" => "Repository leveraging Github features to handle contributions from the community", + "fork" => false, + "url" => "https://api.github.com/repos/Benefactorum/contributions", + "forks_url" => "https://api.github.com/repos/Benefactorum/contributions/forks", + "keys_url" => "https://api.github.com/repos/Benefactorum/contributions/keys{/key_id}", + "collaborators_url" => "https://api.github.com/repos/Benefactorum/contributions/collaborators{/collaborator}", + "teams_url" => "https://api.github.com/repos/Benefactorum/contributions/teams", + "hooks_url" => "https://api.github.com/repos/Benefactorum/contributions/hooks", + "issue_events_url" => "https://api.github.com/repos/Benefactorum/contributions/issues/events{/number}", + "events_url" => "https://api.github.com/repos/Benefactorum/contributions/events", + "assignees_url" => "https://api.github.com/repos/Benefactorum/contributions/assignees{/user}", + "branches_url" => "https://api.github.com/repos/Benefactorum/contributions/branches{/branch}", + "tags_url" => "https://api.github.com/repos/Benefactorum/contributions/tags", + "blobs_url" => "https://api.github.com/repos/Benefactorum/contributions/git/blobs{/sha}", + "git_tags_url" => "https://api.github.com/repos/Benefactorum/contributions/git/tags{/sha}", + "git_refs_url" => "https://api.github.com/repos/Benefactorum/contributions/git/refs{/sha}", + "trees_url" => "https://api.github.com/repos/Benefactorum/contributions/git/trees{/sha}", + "statuses_url" => "https://api.github.com/repos/Benefactorum/contributions/statuses/{sha}", + "languages_url" => "https://api.github.com/repos/Benefactorum/contributions/languages", + "stargazers_url" => "https://api.github.com/repos/Benefactorum/contributions/stargazers", + "contributors_url" => "https://api.github.com/repos/Benefactorum/contributions/contributors", + "subscribers_url" => "https://api.github.com/repos/Benefactorum/contributions/subscribers", + "subscription_url" => "https://api.github.com/repos/Benefactorum/contributions/subscription", + "commits_url" => "https://api.github.com/repos/Benefactorum/contributions/commits{/sha}", + "git_commits_url" => "https://api.github.com/repos/Benefactorum/contributions/git/commits{/sha}", + "comments_url" => "https://api.github.com/repos/Benefactorum/contributions/comments{/number}", + "issue_comment_url" => "https://api.github.com/repos/Benefactorum/contributions/issues/comments{/number}", + "contents_url" => "https://api.github.com/repos/Benefactorum/contributions/contents/{+path}", + "compare_url" => "https://api.github.com/repos/Benefactorum/contributions/compare/{base}...{head}", + "merges_url" => "https://api.github.com/repos/Benefactorum/contributions/merges", + "archive_url" => "https://api.github.com/repos/Benefactorum/contributions/{archive_format}{/ref}", + "downloads_url" => "https://api.github.com/repos/Benefactorum/contributions/downloads", + "issues_url" => "https://api.github.com/repos/Benefactorum/contributions/issues{/number}", + "pulls_url" => "https://api.github.com/repos/Benefactorum/contributions/pulls{/number}", + "milestones_url" => "https://api.github.com/repos/Benefactorum/contributions/milestones{/number}", + "notifications_url" => "https://api.github.com/repos/Benefactorum/contributions/notifications{?since,all,participating}", + "labels_url" => "https://api.github.com/repos/Benefactorum/contributions/labels{/name}", + "releases_url" => "https://api.github.com/repos/Benefactorum/contributions/releases{/id}", + "deployments_url" => "https://api.github.com/repos/Benefactorum/contributions/deployments", + "created_at" => "2025-03-06T10:53:39Z", + "updated_at" => "2025-03-07T13:11:30Z", + "pushed_at" => "2025-04-03T13:26:58Z", + "git_url" => "git://github.com/Benefactorum/contributions.git", + "ssh_url" => "git@github.com:Benefactorum/contributions.git", + "clone_url" => "https://github.com/Benefactorum/contributions.git", + "svn_url" => "https://github.com/Benefactorum/contributions", + "homepage" => nil, + "size" => 14, + "stargazers_count" => 0, + "watchers_count" => 0, + "language" => nil, + "has_issues" => true, + "has_projects" => false, + "has_downloads" => true, + "has_wiki" => true, + "has_pages" => false, + "has_discussions" => true, + "forks_count" => 0, + "mirror_url" => nil, + "archived" => false, + "disabled" => false, + "open_issues_count" => 1, + "license" => + { + "key" => "gpl-3.0", + "name" => "GNU General Public License v3.0", + "spdx_id" => "GPL-3.0", + "url" => "https://api.github.com/licenses/gpl-3.0", + "node_id" => "MDc6TGljZW5zZTk=" + }, + "allow_forking" => true, + "is_template" => false, + "web_commit_signoff_required" => false, + "topics" => [], + "visibility" => "public", + "forks" => 0, + "open_issues" => 1, + "watchers" => 0, + "default_branch" => "main", + "allow_squash_merge" => true, + "allow_merge_commit" => true, + "allow_rebase_merge" => true, + "allow_auto_merge" => true, + "delete_branch_on_merge" => true, + "allow_update_branch" => false, + "use_squash_pr_title_as_default" => false, + "squash_merge_commit_message" => "COMMIT_MESSAGES", + "squash_merge_commit_title" => "COMMIT_OR_PR_TITLE", + "merge_commit_message" => "PR_TITLE", + "merge_commit_title" => "MERGE_MESSAGE" + } + }, + "base" => + { + "label" => "Benefactorum:main", + "ref" => "main", + "sha" => "e04a6b56a9d85bb385df887ac23458d6470e7396", + "user" => + { + "login" => "Benefactorum", + "id" => 143507729, + "node_id" => "O_kgDOCI3BEQ", + "avatar_url" => "https://avatars.githubusercontent.com/u/143507729?v=4", + "gravatar_id" => "", + "url" => "https://api.github.com/users/Benefactorum", + "html_url" => "https://github.com/Benefactorum", + "followers_url" => "https://api.github.com/users/Benefactorum/followers", + "following_url" => "https://api.github.com/users/Benefactorum/following{/other_user}", + "gists_url" => "https://api.github.com/users/Benefactorum/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/Benefactorum/starred{/owner}{/repo}", + "subscriptions_url" => "https://api.github.com/users/Benefactorum/subscriptions", + "organizations_url" => "https://api.github.com/users/Benefactorum/orgs", + "repos_url" => "https://api.github.com/users/Benefactorum/repos", + "events_url" => "https://api.github.com/users/Benefactorum/events{/privacy}", + "received_events_url" => "https://api.github.com/users/Benefactorum/received_events", + "type" => "Organization", + "user_view_type" => "public", + "site_admin" => false + }, + "repo" => + { + "id" => 943838474, + "node_id" => "R_kgDOOEHVCg", + "name" => "contributions", + "full_name" => "Benefactorum/contributions", + "private" => false, + "owner" => + { + "login" => "Benefactorum", + "id" => 143507729, + "node_id" => "O_kgDOCI3BEQ", + "avatar_url" => "https://avatars.githubusercontent.com/u/143507729?v=4", + "gravatar_id" => "", + "url" => "https://api.github.com/users/Benefactorum", + "html_url" => "https://github.com/Benefactorum", + "followers_url" => "https://api.github.com/users/Benefactorum/followers", + "following_url" => "https://api.github.com/users/Benefactorum/following{/other_user}", + "gists_url" => "https://api.github.com/users/Benefactorum/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/Benefactorum/starred{/owner}{/repo}", + "subscriptions_url" => "https://api.github.com/users/Benefactorum/subscriptions", + "organizations_url" => "https://api.github.com/users/Benefactorum/orgs", + "repos_url" => "https://api.github.com/users/Benefactorum/repos", + "events_url" => "https://api.github.com/users/Benefactorum/events{/privacy}", + "received_events_url" => "https://api.github.com/users/Benefactorum/received_events", + "type" => "Organization", + "user_view_type" => "public", + "site_admin" => false + }, + "html_url" => "https://github.com/Benefactorum/contributions", + "description" => "Repository leveraging Github features to handle contributions from the community", + "fork" => false, + "url" => "https://api.github.com/repos/Benefactorum/contributions", + "forks_url" => "https://api.github.com/repos/Benefactorum/contributions/forks", + "keys_url" => "https://api.github.com/repos/Benefactorum/contributions/keys{/key_id}", + "collaborators_url" => "https://api.github.com/repos/Benefactorum/contributions/collaborators{/collaborator}", + "teams_url" => "https://api.github.com/repos/Benefactorum/contributions/teams", + "hooks_url" => "https://api.github.com/repos/Benefactorum/contributions/hooks", + "issue_events_url" => "https://api.github.com/repos/Benefactorum/contributions/issues/events{/number}", + "events_url" => "https://api.github.com/repos/Benefactorum/contributions/events", + "assignees_url" => "https://api.github.com/repos/Benefactorum/contributions/assignees{/user}", + "branches_url" => "https://api.github.com/repos/Benefactorum/contributions/branches{/branch}", + "tags_url" => "https://api.github.com/repos/Benefactorum/contributions/tags", + "blobs_url" => "https://api.github.com/repos/Benefactorum/contributions/git/blobs{/sha}", + "git_tags_url" => "https://api.github.com/repos/Benefactorum/contributions/git/tags{/sha}", + "git_refs_url" => "https://api.github.com/repos/Benefactorum/contributions/git/refs{/sha}", + "trees_url" => "https://api.github.com/repos/Benefactorum/contributions/git/trees{/sha}", + "statuses_url" => "https://api.github.com/repos/Benefactorum/contributions/statuses/{sha}", + "languages_url" => "https://api.github.com/repos/Benefactorum/contributions/languages", + "stargazers_url" => "https://api.github.com/repos/Benefactorum/contributions/stargazers", + "contributors_url" => "https://api.github.com/repos/Benefactorum/contributions/contributors", + "subscribers_url" => "https://api.github.com/repos/Benefactorum/contributions/subscribers", + "subscription_url" => "https://api.github.com/repos/Benefactorum/contributions/subscription", + "commits_url" => "https://api.github.com/repos/Benefactorum/contributions/commits{/sha}", + "git_commits_url" => "https://api.github.com/repos/Benefactorum/contributions/git/commits{/sha}", + "comments_url" => "https://api.github.com/repos/Benefactorum/contributions/comments{/number}", + "issue_comment_url" => "https://api.github.com/repos/Benefactorum/contributions/issues/comments{/number}", + "contents_url" => "https://api.github.com/repos/Benefactorum/contributions/contents/{+path}", + "compare_url" => "https://api.github.com/repos/Benefactorum/contributions/compare/{base}...{head}", + "merges_url" => "https://api.github.com/repos/Benefactorum/contributions/merges", + "archive_url" => "https://api.github.com/repos/Benefactorum/contributions/{archive_format}{/ref}", + "downloads_url" => "https://api.github.com/repos/Benefactorum/contributions/downloads", + "issues_url" => "https://api.github.com/repos/Benefactorum/contributions/issues{/number}", + "pulls_url" => "https://api.github.com/repos/Benefactorum/contributions/pulls{/number}", + "milestones_url" => "https://api.github.com/repos/Benefactorum/contributions/milestones{/number}", + "notifications_url" => "https://api.github.com/repos/Benefactorum/contributions/notifications{?since,all,participating}", + "labels_url" => "https://api.github.com/repos/Benefactorum/contributions/labels{/name}", + "releases_url" => "https://api.github.com/repos/Benefactorum/contributions/releases{/id}", + "deployments_url" => "https://api.github.com/repos/Benefactorum/contributions/deployments", + "created_at" => "2025-03-06T10:53:39Z", + "updated_at" => "2025-03-07T13:11:30Z", + "pushed_at" => "2025-04-03T13:26:58Z", + "git_url" => "git://github.com/Benefactorum/contributions.git", + "ssh_url" => "git@github.com:Benefactorum/contributions.git", + "clone_url" => "https://github.com/Benefactorum/contributions.git", + "svn_url" => "https://github.com/Benefactorum/contributions", + "homepage" => nil, + "size" => 14, + "stargazers_count" => 0, + "watchers_count" => 0, + "language" => nil, + "has_issues" => true, + "has_projects" => false, + "has_downloads" => true, + "has_wiki" => true, + "has_pages" => false, + "has_discussions" => true, + "forks_count" => 0, + "mirror_url" => nil, + "archived" => false, + "disabled" => false, + "open_issues_count" => 1, + "license" => + { + "key" => "gpl-3.0", + "name" => "GNU General Public License v3.0", + "spdx_id" => "GPL-3.0", + "url" => "https://api.github.com/licenses/gpl-3.0", + "node_id" => "MDc6TGljZW5zZTk=" + }, + "allow_forking" => true, + "is_template" => false, + "web_commit_signoff_required" => false, + "topics" => [], + "visibility" => "public", + "forks" => 0, + "open_issues" => 1, + "watchers" => 0, + "default_branch" => "main", + "allow_squash_merge" => true, + "allow_merge_commit" => true, + "allow_rebase_merge" => true, + "allow_auto_merge" => true, + "delete_branch_on_merge" => true, + "allow_update_branch" => false, + "use_squash_pr_title_as_default" => false, + "squash_merge_commit_message" => "COMMIT_MESSAGES", + "squash_merge_commit_title" => "COMMIT_OR_PR_TITLE", + "merge_commit_message" => "PR_TITLE", + "merge_commit_title" => "MERGE_MESSAGE" + } + }, + "_links" => + { + "self" => { + "href" => "https://api.github.com/repos/Benefactorum/contributions/pulls/31" + }, + "html" => { + "href" => "https://github.com/Benefactorum/contributions/pull/31" + }, + "issue" => { + "href" => "https://api.github.com/repos/Benefactorum/contributions/issues/31" + }, + "comments" => { + "href" => "https://api.github.com/repos/Benefactorum/contributions/issues/31/comments" + }, + "review_comments" => { + "href" => "https://api.github.com/repos/Benefactorum/contributions/pulls/31/comments" + }, + "review_comment" => { + "href" => "https://api.github.com/repos/Benefactorum/contributions/pulls/comments{/number}" + }, + "commits" => { + "href" => "https://api.github.com/repos/Benefactorum/contributions/pulls/31/commits" + }, + "statuses" => { + "href" => "https://api.github.com/repos/Benefactorum/contributions/statuses/d82bb33be655ac11075b8f49346395fdecf69586" + } + }, + "author_association" => "NONE", + "auto_merge" => nil, + "active_lock_reason" => nil + }, + "sender" => { + "login" => "mpressen", + "id" => 16125283, + "node_id" => "MDQ6VXNlcjE2MTI1Mjgz", + "avatar_url" => "https://avatars.githubusercontent.com/u/16125283?v=4", + "gravatar_id" => "", + "url" => "https://api.github.com/users/mpressen", + "html_url" => "https://github.com/mpressen", + "followers_url" => "https://api.github.com/users/mpressen/followers", + "following_url" => "https://api.github.com/users/mpressen/following{/other_user}", + "gists_url" => "https://api.github.com/users/mpressen/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/mpressen/starred{/owner}{/repo}", + "subscriptions_url" => "https://api.github.com/users/mpressen/subscriptions", + "organizations_url" => "https://api.github.com/users/mpressen/orgs", + "repos_url" => "https://api.github.com/users/mpressen/repos", + "events_url" => "https://api.github.com/users/mpressen/events{/privacy}", + "received_events_url" => "https://api.github.com/users/mpressen/received_events", + "type" => "User", + "user_view_type" => "public", + "site_admin" => false + } + } + end + end +end diff --git a/spec/models/github_event_spec.rb b/spec/models/github_event_spec.rb new file mode 100644 index 00000000..dde28751 --- /dev/null +++ b/spec/models/github_event_spec.rb @@ -0,0 +1,9 @@ +require "rails_helper" + +RSpec.describe GithubEvent, type: :model do + describe "factory" do + it "has a valid factory" do + expect(build(:github_event)).to be_valid + end + end +end diff --git a/spec/services/github_events/create_service_spec.rb b/spec/services/github_events/create_service_spec.rb new file mode 100644 index 00000000..fffbd766 --- /dev/null +++ b/spec/services/github_events/create_service_spec.rb @@ -0,0 +1,34 @@ +require "rails_helper" + +RSpec.describe GithubEvents::CreateService do + describe "#call" do + subject { described_class.new(github_event:).call } + context "when event is pull_request_review" do + let(:github_event) { create(:github_event) } + + before do + create(:contribution, status: "en attente de validation", github_resource_url: github_event.payload["pull_request"]["html_url"]) + end + + context "when changes are requested" do + it "sets the related contribution model statuts to 'modifications demandées'" do + subject + expect(github_event.reload.contribution.status).to eq("modifications demandées") + expect(github_event.status).to eq("processed") + end + end + + context "when the review is approved" do + before do + github_event.payload["review"]["state"] = "approved" + end + + it "creates an OSBL and sets the related contribution model statuts to 'validée'" do + expect { subject }.to change { Osbl.count }.by(1) + expect(github_event.reload.contribution.status).to eq("validée") + expect(github_event.status).to eq("processed") + end + end + end + end +end