@@ -643,23 +643,35 @@ defmodule Algora.Workspace do
643
643
def list_user_contributions ( ids , opts \\ [ ] ) do
644
644
query =
645
645
from uc in UserContribution ,
646
+ where: uc . user_id in ^ ids ,
646
647
join: u in assoc ( uc , :user ) ,
647
648
join: r in assoc ( uc , :repository ) ,
648
649
join: repo_owner in assoc ( r , :user ) ,
649
- where: u . id in ^ ids ,
650
- where: not ilike ( r . name , "%awesome%" ) ,
651
- where: not ilike ( r . name , "%algorithms%" ) ,
652
- where: not ilike ( r . name , "%exercises%" ) ,
653
- where: not ilike ( r . name , "%tutorials%" ) ,
654
- where: not ilike ( repo_owner . provider_login , "%algorithms%" ) ,
655
- where: not ilike ( repo_owner . provider_login , "%firstcontributions%" ) ,
656
650
where: repo_owner . type == :organization or r . stargazers_count > 200 ,
657
651
# where: fragment("? && ?::citext[]", r.tech_stack, ^(opts[:tech_stack] || [])),
652
+ where:
653
+ not ( ilike ( r . name , "%awesome%" ) or
654
+ ilike ( r . name , "%algorithms%" ) or
655
+ ilike ( r . name , "%exercises%" ) or
656
+ ilike ( r . name , "%tutorials%" ) ) ,
657
+ where:
658
+ not ( ilike ( repo_owner . provider_login , "%algorithms%" ) or
659
+ ilike ( repo_owner . provider_login , "%firstcontributions%" ) ) ,
658
660
order_by: [
659
661
desc: fragment ( "CASE WHEN ? && ?::citext[] THEN 1 ELSE 0 END" , r . tech_stack , ^ ( opts [ :tech_stack ] || [ ] ) ) ,
660
662
desc: r . stargazers_count
661
663
] ,
662
- select_merge: % { user: u , repository: % { r | user: repo_owner } }
664
+ select: % UserContribution {
665
+ contribution_count: uc . contribution_count ,
666
+ user: map ( u , [ :id , :provider_login ] ) ,
667
+ repository: % {
668
+ id: r . id ,
669
+ name: r . name ,
670
+ stargazers_count: r . stargazers_count ,
671
+ tech_stack: r . tech_stack ,
672
+ user: map ( repo_owner , [ :id , :provider_login , :type , :name , :avatar_url , :stargazers_count ] )
673
+ }
674
+ }
663
675
664
676
query =
665
677
case opts [ :limit ] do
@@ -748,11 +760,17 @@ defmodule Algora.Workspace do
748
760
|> Oban . insert ( )
749
761
750
762
_ ->
763
+ Logger . error ( "User not found for #{ contribution . provider_login } " )
751
764
{ :error , :user_not_found }
752
765
end
753
766
end )
754
767
755
- if Enum . any? ( results , & match? ( { :ok , _ } , & 1 ) ) , do: :ok , else: { :error , :failed }
768
+ if Enum . any? ( results , & match? ( { :ok , _ } , & 1 ) ) do
769
+ :ok
770
+ else
771
+ Logger . error ( "Failed to add contributions: #{ inspect ( results ) } " )
772
+ { :error , :failed }
773
+ end
756
774
end
757
775
758
776
defp add_contributions ( token , users , contributions ) do
0 commit comments