Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Commit

Permalink
Fix opening PR (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
vegaro authored Aug 16, 2023
1 parent b35c989 commit 2afb3e2
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ lane :open_syncing_pr do |options|
readme_api_key = ENV["RDME_API_KEY"]
UI.user_error!("Missing README API key") unless readme_api_key

github_pr_token = ENV["GITHUB_API_TOKEN"]

latest_commit_sha = get_latest_commit_sha

current_version = get_current_version

new_branch_name = "sync/#{current_version}"

validate_local_config_status_for_bump(new_branch_name)
validate_local_config_status_for_bump(new_branch_name, github_pr_token)

create_version_if_needed(current_version, readme_api_key)

Expand All @@ -87,7 +89,7 @@ lane :open_syncing_pr do |options|

if git_repo_dirty?
commit_changes_and_push_current_branch("Rendered docs for commit #{latest_commit_sha}")
create_pr_to_main(pr_title, body, REPO_NAME, new_branch_name, [])
create_pr_to_main(pr_title, body, REPO_NAME, new_branch_name, github_pr_token, [])
else
UI.message("Repository is clean. Nothing to commit.")
end
Expand All @@ -107,7 +109,7 @@ desc "Embeds code blocks from all files within the [block:file] and [/block] tag
lane :post_circleci_artifacts do |options|
circleci_build_num = ENV['CIRCLE_BUILD_NUM']
circleci_token = ENV['CIRCLE_TOKEN']
github_token = ENV['GITHUB_TOKEN']
github_token = ENV['GITHUB_API_TOKEN']

post_circleci_artifacts(circleci_build_num, circleci_token, github_token)
end
Expand Down Expand Up @@ -305,9 +307,8 @@ def git_repo_dirty?
end

# Replace with fastlane plugin's
def validate_local_config_status_for_bump(new_branch)
def validate_local_config_status_for_bump(new_branch, github_pr_token)
# Ensure GitHub API token is set
github_pr_token = ENV["GITHUB_API_TOKEN"]
if github_pr_token.nil? || github_pr_token.empty?
UI.error("A github_pr_token parameter or an environment variable GITHUB_API_TOKEN is required to create a pull request")
UI.error("Please make a fastlane/.env file from the fastlane/.env.SAMPLE template")
Expand Down Expand Up @@ -352,8 +353,9 @@ def commit_current_changes(commit_message)
sh("git commit -am '#{commit_message}'")
end

def create_pr_to_main(title, body, repo_name, head_branch, labels = [])
def create_pr_to_main(title, body, repo_name, head_branch, github_pr_token, labels = [])
Actions::CreatePullRequestAction.run(
api_token: github_pr_token,
title: title,
base: 'main',
body: body,
Expand Down

0 comments on commit 2afb3e2

Please sign in to comment.