Skip to content

Instantly share code, notes, and snippets.

@mdb1
Last active August 15, 2023 17:44
Show Gist options
  • Save mdb1/ae7ba3ae6056449b317c873f5417b24f to your computer and use it in GitHub Desktop.
Save mdb1/ae7ba3ae6056449b317c873f5417b24f to your computer and use it in GitHub Desktop.
Fastlane PR Lane example
default_platform(:ios)
GITHUB_REPO_NAME="your-repo-name" # Example: mdb1/fastlane-example
GIT_DEFAULT_BRANCH="main"
platform :ios do
desc "Description of what the lane does"
lane :custom_lane do
# add actions here: https://docs.fastlane.tools/actions
end
desc 'Prompt information and then create a Pull Request on Github'
desc 'Options:'
desc 'draft --- Determines if the PR is a draft or not (Default: false).'
lane :pr do |options|
# Check --draft param
isDraft = options[:draft].nil? ? false : options[:draft]
UI.message "Showing commit diff with main:"
sh("git log --oneline --reverse main.. --pretty=format:'%s'")
# Ask for the PR Title
UI.message("Enter the PR title:")
pr_title = STDIN.gets.chomp
# Ask the user for the PR description
pr_body = prompt_pr_description
# Create the PR on GitHub.
pr_url = create_pull_request(
repo: GITHUB_REPO_NAME,
title: pr_title,
body: pr_body,
draft: isDraft,
base: GIT_DEFAULT_BRANCH
)
# Open the pull request URL in the default web browser
sh("open #{pr_url}")
end
# Prompts information about a PR's description
def prompt_pr_description
pr_body = ""
# Ask the user for the PR body
UI.message("Enter the PR body (multiline text, press Ctrl+D on an empty line to finish):")
while (line = STDIN.gets)
pr_body += line
end
# Ask the user for the screenshot option and generate the markdown table
screenshots_table = prompt_screenshots_table
# Format the PR body as Markdown text
markdown_text = <<~MARKDOWN
## Description
#{pr_body}
#{screenshots_table}
MARKDOWN
return markdown_text
end
# Let the user select an option to generate a markdown table for screenshots.
def prompt_screenshots_table
table_options = [
"No screenshots",
"Table: 1 column 1 row",
"Table: 2 columns 1 row",
"Table: 2 columns 2 rows",
"Table: 3 columns 1 row",
"Table: 3 columns 2 rows"
]
# Ask the user for the screenshot option
screenshot_option = nil
loop do
UI.message("Choose the screenshot option:")
table_options.each_with_index { |option, index| UI.message("#{index + 1}. #{option}") }
choice = UI.input("Enter the option number (1-#{table_options.size}):")
choice_index = choice.to_i - 1
if choice_index >= 0 && choice_index < table_options.size
screenshot_option = table_options[choice_index]
break
else
UI.error("Invalid option. Please enter a valid option number.")
end
end
# Generate the markdown table based on the selected option
case screenshot_option
when "Table: 1 column 1 row"
markdown_table = <<~MARKDOWN
## Screenshots
| Title 1 |
| - |
| IMG 1 |
MARKDOWN
when "Table: 2 columns 1 row"
markdown_table = <<~MARKDOWN
## Screenshots
| Title 1 | Title 2 |
| - | - |
| IMG 1 | IMG 2 |
MARKDOWN
when "Table: 2 columns 2 rows"
markdown_table = <<~MARKDOWN
## Screenshots
| Title 1 | Title 2 |
| - | - |
| IMG 1 | IMG 2 |
| IMG 3 | IMG 4 |
MARKDOWN
when "Table: 3 columns 1 row"
markdown_table = <<~MARKDOWN
## Screenshots
| Title 1 | Title 2 | Title 3 |
| - | - | - |
| IMG 1 | IMG 2 | IMG 3 |
MARKDOWN
when "Table: 3 columns 2 rows"
markdown_table = <<~MARKDOWN
## Screenshots
| Title 1 | Title 2 | Title 3 |
| - | - | - |
| IMG 1 | IMG 2 | IMG 3 |
| IMG 4 | IMG 5 | IMG 6 |
MARKDOWN
else
markdown_table = ""
end
return markdown_table
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment