diff --git a/fastlane/Fastfile b/fastlane/Fastfile index e362469..e95d1a8 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -134,4 +134,13 @@ lane :test do basic_creds: "username:password", request_id: "pr-id" ) + + bitbucket_fetch_changed_lines_between_two_commits( + project_key: 'my-project', + repo_slug: 'my-repo', + basic_creds: "username:password" + source_commit: "abcd1234", + destination_commit: "efgh5678", + prefix: "+" + ) end \ No newline at end of file diff --git a/lib/fastlane/plugin/bitbucket/actions/bitbucket_fetch_changed_lines_between_two_commits_action.rb b/lib/fastlane/plugin/bitbucket/actions/bitbucket_fetch_changed_lines_between_two_commits_action.rb new file mode 100644 index 0000000..b46d5e0 --- /dev/null +++ b/lib/fastlane/plugin/bitbucket/actions/bitbucket_fetch_changed_lines_between_two_commits_action.rb @@ -0,0 +1,117 @@ +require 'fastlane/action' +require_relative '../helper/bitbucket_helper' +require 'base64' + + +module Fastlane + module Actions + class BitbucketFetchChangedLinesBetweenTwoCommitsAction < Action + def self.run(params) + auth_header = Helper::BitbucketHelper.get_auth_header(params) + + if params[:base_url] then + base_url = params[:base_url] + else + base_url = 'https://api.bitbucket.org' + end + + if params[:prefix] then + prefix = params[:prefix] + else + prefix = '' + end + + changed_lines = Helper::BitbucketHelper.compare_two_commits(auth_header, base_url, params[:project_key], params[:repo_slug], params[:source_commit], params[:destination_commit]) + + lines_with_prefix = "" + changed_lines.each_line do |line| + if line.start_with?(prefix) + lines_with_prefix.concat(line.delete_prefix(prefix)) + end + end + + lines_with_prefix + end + + def self.description + "This action allows fastlane to filter two commits diff by a specific prefix" + end + + def self.authors + ["Daniel Nazareth"] + end + + def self.return_value + "The return value is a string with the diff that start with a specifc prefix between two commits" + end + + def self.available_options + [ + FastlaneCore::ConfigItem.new( + key: :base_url, + env_name: "BITBUCKET_BASE_URL", + description: "The base URL for your BitBucket Server, including protocol", + optional: true, + type: String, + verify_block: proc do |value| + UI.user_error!("Bitbucket Server url should use https") unless !!(value.match"^https://") + end + ), + FastlaneCore::ConfigItem.new( + key: :project_key, + env_name: "BITBUCKET_PROJECT_KEY", + description: "The Project Key for your repository", + optional: false, + type: String + ), + FastlaneCore::ConfigItem.new( + key: :repo_slug, + env_name: "BITBUCKET_REPO_SLUG", + description: "The repository slug for your repository", + optional: false, + type: String + ), + FastlaneCore::ConfigItem.new( + key: :access_token, + env_name: "BITBUCKET_PERSONAL_ACCESS_TOKEN", + description: "A Personal Access Token from BitBucket for the account used. One of access_token or basic_creds must be specified; if both are supplied access_token is used", + optional: true, + type: String + ), + FastlaneCore::ConfigItem.new( + key: :basic_creds, + env_name: "BITBUCKET_BASIC_AUTH_CREDENTIALS", + description: "To use Basic Auth for Bitbuket provide a base64 encoded version of \":\". One of access_token or basic_creds must be specified; if both are supplied access_token is used", + optional: true, + type: String + ), + FastlaneCore::ConfigItem.new( + key: :source_commit, + env_name: "BITBUCKET_DIFFSTAT_SOURCE_COMMIT", + description: "The hash of commit from origin branch", + optional: false, + type: String + ), + FastlaneCore::ConfigItem.new( + key: :destination_commit, + env_name: "BITBUCKET_DIFFSTAT_DESTINATION_COMMIT", + description: "The hash of commit from destination branch", + optional: false, + type: String + ), + FastlaneCore::ConfigItem.new( + key: :prefix, + env_name: "BITBUCKET_COMMIT_CHANGE_PREFIX", + description: "The prefix that indicate the desired change on a commit", + optional: true, + type: String + ) + ] + end + + def self.is_supported?(platform) + true + end + end + end +end \ No newline at end of file diff --git a/lib/fastlane/plugin/bitbucket/helper/bitbucket_helper.rb b/lib/fastlane/plugin/bitbucket/helper/bitbucket_helper.rb index 0b6e14b..4cc8919 100644 --- a/lib/fastlane/plugin/bitbucket/helper/bitbucket_helper.rb +++ b/lib/fastlane/plugin/bitbucket/helper/bitbucket_helper.rb @@ -213,6 +213,12 @@ def self.get_branching_model(access_header, baseurl, project_key, repo_slug) data end + def self.compare_two_commits(access_header, baseurl, project_key, repo_slug, source_commit, destination_commit) + uri = URI.parse("#{baseurl}/2.0/repositories/#{project_key}/#{repo_slug}/diff/#{source_commit}%0D#{destination_commit}") + prresp = self.perform_get(uri, access_header, {}) + data = prresp.body + data + end end end end diff --git a/lib/fastlane/plugin/bitbucket/version.rb b/lib/fastlane/plugin/bitbucket/version.rb index 03106ee..0128307 100644 --- a/lib/fastlane/plugin/bitbucket/version.rb +++ b/lib/fastlane/plugin/bitbucket/version.rb @@ -1,5 +1,5 @@ module Fastlane module Bitbucket - VERSION = "0.1.20" + VERSION = "0.1.21" end end