@@ -654,12 +654,10 @@ defmodule Algora.Workspace do
654
654
end
655
655
end
656
656
657
- def fetch_top_contributions ( provider_login ) do
658
- token = Algora.Admin . token ( )
659
-
657
+ def fetch_top_contributions ( token , provider_login ) do
660
658
with { :ok , contributions } <- Algora.Cloud . top_contributions ( provider_login ) ,
661
659
{ :ok , user } <- ensure_user ( token , provider_login ) ,
662
- :ok <- add_contributions ( user . id , contributions ) do
660
+ :ok <- add_contributions ( token , user . id , contributions ) do
663
661
{ :ok , contributions }
664
662
else
665
663
{ :error , reason } ->
@@ -668,12 +666,10 @@ defmodule Algora.Workspace do
668
666
end
669
667
end
670
668
671
- def fetch_top_contributions_async ( provider_login ) do
672
- token = Algora.Admin . token ( )
673
-
669
+ def fetch_top_contributions_async ( token , provider_login ) do
674
670
with { :ok , contributions } <- Algora.Cloud . top_contributions ( provider_login ) ,
675
671
{ :ok , user } <- ensure_user ( token , provider_login ) ,
676
- { :ok , _ } <- add_contributions_async ( user . id , contributions ) do
672
+ { :ok , _ } <- add_contributions_async ( token , user . id , contributions ) do
677
673
{ :ok , nil }
678
674
else
679
675
{ :error , reason } ->
@@ -682,7 +678,7 @@ defmodule Algora.Workspace do
682
678
end
683
679
end
684
680
685
- def add_contributions_async ( user_id , opts ) do
681
+ def add_contributions_async ( _token , user_id , opts ) do
686
682
Repo . transact ( fn ->
687
683
Enum . reduce_while ( opts , :ok , fn contribution , _ ->
688
684
case % {
@@ -699,18 +695,26 @@ defmodule Algora.Workspace do
699
695
end )
700
696
end
701
697
702
- def add_contributions ( user_id , opts ) do
698
+ def add_contributions ( token , user_id , opts ) do
703
699
results =
704
700
Enum . map ( opts , fn % { repo_name: repo_name , contribution_count: contribution_count } ->
705
- add_contribution ( % { user_id: user_id , repo_full_name: repo_name , contribution_count: contribution_count } )
701
+ add_contribution ( % {
702
+ token: token ,
703
+ user_id: user_id ,
704
+ repo_full_name: repo_name ,
705
+ contribution_count: contribution_count
706
+ } )
706
707
end )
707
708
708
709
if Enum . any? ( results , fn result -> result == :ok end ) , do: :ok , else: { :error , :failed }
709
710
end
710
711
711
- def add_contribution ( % { user_id: user_id , repo_full_name: repo_full_name , contribution_count: contribution_count } ) do
712
- token = Algora.Admin . token ( )
713
-
712
+ def add_contribution ( % {
713
+ token: token ,
714
+ user_id: user_id ,
715
+ repo_full_name: repo_full_name ,
716
+ contribution_count: contribution_count
717
+ } ) do
714
718
with [ repo_owner , repo_name ] <- String . split ( repo_full_name , "/" ) ,
715
719
{ :ok , repo } <- ensure_repository ( token , repo_owner , repo_name ) ,
716
720
{ :ok , _tech_stack } <- ensure_repo_tech_stack ( token , repo ) ,
0 commit comments