Skip to content

Commit

Permalink
Add get user id for github handle action
Browse files Browse the repository at this point in the history
  • Loading branch information
jaceklyp committed Sep 2, 2024
1 parent a207fde commit e4a1c35
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
require "fastlane/action"
require "fastlane_core/configuration/config_item"
require "yaml"
require_relative "../helper/ddg_apple_automation_helper"
require_relative "../helper/github_actions_helper"

module Fastlane
module Actions
class AsanaGetUserIdForGithubHandleAction < Action
def self.run(params)
token = params[:asana_access_token]
github_handle = params[:github_handle]

mapping_file = File.expand_path('assets/github-asana-user-id-mapping.yml', __dir__)
user_mapping = YAML.load_file(mapping_file)
asana_user_id = user_mapping[github_handle]

if asana_user_id.nil? || asana_user_id.to_s.empty?
UI.user_error!("Asana User ID not found for GitHub handle: #{github_handle}")
else
Helper::GitHubActionsHelper.set_output("user-id", asana_user_id)
asana_user_id
end
end

def self.description
"This action returns Asana user ID that matches GitHub user handle"
end

def self.authors
["DuckDuckGo"]
end

def self.return_value
"User ID that matches GitHub user handle"
end

def self.details
# Optional:
""
end

def self.available_options
[
FastlaneCore::ConfigItem.asana_access_token,
FastlaneCore::ConfigItem.new(key: :github_handle,
description: "Github user handle",
optional: false,
type: String)
]
end

def self.is_supported?(platform)
true
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
aataraxiaa: "1206488453854239"
afterxleep: "1204051006248664"
alessandroboron: "1206329551987270"
amddg44: "1201462886797771"
ayoy: "1201621708091911"
brindy: "33604954490307"
Bunn: "1201011656757987"
bwaresiak: "856498666990313"
dharb: "246491496396026"
diegoreymendez: "1203108348749442"
dus7: "1206226850447383"
federicocappelli: "1205736672764360"
GioSensation: "1144596632862977"
graeme: "1202926619863343"
jaceklyp: "1201392122268514"
jonathanKingston: "1199237043579003"
jotaemepereira: "1203972458584419"
kshann: "1205419239089228"
ladamski: "1171671023737946"
loremattei: "1202204871961729"
mallexxx: "1202406491309495"
miasma13: "1200848783415037"
muodov: "1201807839780469"
quanganhdo: "1205591970852428"
SabrinaTardio: "1204024359086948"
samsymons: "1193060753332998"
shakyShane: "1201141132903155"
THISISDINOSAUR: "1187352150204278"
tomasstrba: "1148564398679340"
viktorjansson: "970019367293722"
vinay-nadig-0042: "1202096681806170"
42 changes: 42 additions & 0 deletions spec/asana_get_user_id_for_github_handle_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
describe Fastlane::Actions::AsanaGetUserIdForGithubHandleAction do
describe "#run" do
let(:yaml_content) do
{
"duck" => "123",
"goose" => "456",
"pigeon" => nil,
"hawk" => ""
}
end

before do
allow(YAML).to receive(:load_file).and_return(yaml_content)
end

it "sets the user ID output and GHA output correctly" do
allow(Fastlane::Helper::GitHubActionsHelper).to receive(:set_output)

expect(test_action("duck")).to eq("123")
expect(Fastlane::Helper::GitHubActionsHelper).to have_received(:set_output).with("user-id", "123")
end

it "shows error when handle does not exist" do
expect(Fastlane::UI).to receive(:user_error!).with("Asana User ID not found for GitHub handle: chicken")
test_action("chicken")
end

it "shows error when handle is nil" do
expect(Fastlane::UI).to receive(:user_error!).with("Asana User ID not found for GitHub handle: pigeon")
test_action("pigeon")
end

it "shows error when handle is empty" do
expect(Fastlane::UI).to receive(:user_error!).with("Asana User ID not found for GitHub handle: hawk")
test_action("hawk")
end
end

def test_action(github_handle)
Fastlane::Actions::AsanaGetUserIdForGithubHandleAction.run(github_handle: github_handle)
end
end

0 comments on commit e4a1c35

Please sign in to comment.