Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add enable auto merge action #56

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions lib/fastlane/plugin/revenuecat_internal/helper/github_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,64 @@ def self.get_releases_between_tags(github_token, start_tag_version, end_tag_vers
start_tag < version && version <= end_tag && !release["prerelease"]
end
end

def self.get_pull_request_id(pull_request_number, github_token)
query_id = <<-GRAPHQL
query QueryId {
repository(name: "revenuecat-docs", owner: "RevenueCat") {
pullRequest(number: #{pull_request_number}) {
id
}
}
}
GRAPHQL

execute_github_graphql_request(
github_token,
query_id,
"Pull request ID queried successfully!",
"Error querying pull request. Pull request ID is nil."
) do |response|
pull_request_id = JSON.parse(response.body)["data"]["repository"]["pullRequest"]["id"]
return pull_request_id unless pull_request_id.nil?
end
end

def self.enable_auto_merge(pull_request_id, github_token)
query_id = <<-GRAPHQL
mutation EnableAutoMerge {
enablePullRequestAutoMerge(input: {pullRequestId: "#{pull_request_id}", mergeMethod: SQUASH}) {
clientMutationId
}
}
GRAPHQL

execute_github_graphql_request(
github_token,
query_id,
"Auto merge enabled successfully!",
"Failed to enable auto merge."
)
end

private_class_method def self.execute_github_graphql_request(github_token, graphql_query, success_message, error_message)
url = URI('https://api.github.com/graphql')
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url.request_uri)
request.basic_auth(github_token, '')
request.body = { query: graphql_query }.to_json

response = http.request(request)
if response.is_a?(Net::HTTPSuccess)
Fastlane::UI.message(success_message)
yield(response) if block_given?
else
Fastlane::UI.user_error!("#{error_message}\nCode: #{response.code}\nBody: #{response.read_body}")
end
end

end
end
end