From 4f0db4d9a5569867c7d6ed78ef6e8a08613303e1 Mon Sep 17 00:00:00 2001 From: Niklas van Schrick Date: Tue, 14 Nov 2023 18:29:22 +0100 Subject: [PATCH] Add support for pull request events --- lib/action/context.rb | 2 +- lib/action/step/clone_project.rb | 3 ++- lib/action/step/prepare_context.rb | 3 ++- lib/action/step/push_branch_to_gitlab.rb | 2 +- lib/action/step/remove_branch_from_gitlab.rb | 2 +- lib/action/step/trigger_pipeline.rb | 2 +- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/action/context.rb b/lib/action/context.rb index 0071334..17bc666 100644 --- a/lib/action/context.rb +++ b/lib/action/context.rb @@ -2,7 +2,7 @@ module GitlabPipelineAction class Context - attr_accessor :gh_project, :gh_sha, :gh_ref, :gh_server_url, + attr_accessor :gh_project, :gh_sha, :gh_ref, :gh_ref_name, :gh_server_url, :gl_server_url, :gl_project_id, :gl_project_path, :gl_runner_token, :gl_api_token, :gl_pipeline, :git_repository, :git_path, diff --git a/lib/action/step/clone_project.rb b/lib/action/step/clone_project.rb index 356af19..d8b4af2 100644 --- a/lib/action/step/clone_project.rb +++ b/lib/action/step/clone_project.rb @@ -9,8 +9,9 @@ def execute context.git_path ) + context.git_repository.fetch('origin', ref: context.gh_ref) context.git_repository.checkout(context.gh_sha) - context.git_repository.branch(context.gh_ref).checkout + context.git_repository.branch(context.gh_ref_name).checkout end end end diff --git a/lib/action/step/prepare_context.rb b/lib/action/step/prepare_context.rb index bb8b209..3bce9b0 100644 --- a/lib/action/step/prepare_context.rb +++ b/lib/action/step/prepare_context.rb @@ -6,7 +6,8 @@ class PrepareContext < Base def execute context.gh_project = ENV.fetch('GITHUB_REPOSITORY', nil) context.gh_sha = ENV.fetch('GITHUB_SHA', nil) - context.gh_ref = ENV.fetch('GITHUB_REF_NAME', nil) + context.gh_ref = ENV.fetch('GITHUB_REF', nil) + context.gh_ref_name = ENV.fetch('GITHUB_REF_NAME', nil) context.gh_server_url = ENV.fetch('GITHUB_SERVER_URL', nil) context.gl_server_url = ENV.fetch('INPUT_GL_SERVER_URL', nil) diff --git a/lib/action/step/push_branch_to_gitlab.rb b/lib/action/step/push_branch_to_gitlab.rb index 8bcf4fc..f264335 100644 --- a/lib/action/step/push_branch_to_gitlab.rb +++ b/lib/action/step/push_branch_to_gitlab.rb @@ -5,7 +5,7 @@ module Step class PushBranchToGitlab < Base def execute context.git_repository.add_remote(GITLAB_REMOTE, gitlab_remote_url) - context.git_repository.push(GITLAB_REMOTE, context.gh_ref, push_option: ['ci.skip']) + context.git_repository.push(GITLAB_REMOTE, context.gh_ref_name, push_option: ['ci.skip']) end private diff --git a/lib/action/step/remove_branch_from_gitlab.rb b/lib/action/step/remove_branch_from_gitlab.rb index 3f54b97..22d9d57 100644 --- a/lib/action/step/remove_branch_from_gitlab.rb +++ b/lib/action/step/remove_branch_from_gitlab.rb @@ -4,7 +4,7 @@ module GitlabPipelineAction module Step class RemoveBranchFromGitlab < Base def execute - context.gitlab_client.delete_branch(context.gl_project_id, context.gh_ref) + context.gitlab_client.delete_branch(context.gl_project_id, context.gh_ref_name) end end end diff --git a/lib/action/step/trigger_pipeline.rb b/lib/action/step/trigger_pipeline.rb index 8b1af14..303e0ed 100644 --- a/lib/action/step/trigger_pipeline.rb +++ b/lib/action/step/trigger_pipeline.rb @@ -6,7 +6,7 @@ class TriggerPipeline < Base def execute context.gl_pipeline = context.gitlab_client.create_pipeline( context.gl_project_id, - context.gh_ref + context.gh_ref_name ) puts "Triggered: #{context.gl_pipeline.web_url}"