Skip to content
This repository
Browse code

Don't use GitHub API to retrieve package versions

  • Loading branch information...
commit 04d4cfbfbd51c79cb7ae2c623db0252d6988526a 1 parent 34363ca
Yurii Rashkovskii authored February 06, 2011

Showing 1 changed file with 93 additions and 18 deletions. Show diff stats Hide diff stats

  1. 111  src/agner_github.erl
111  src/agner_github.erl
@@ -52,27 +52,102 @@ repository(Name) ->
52 52
 	
53 53
 	
54 54
 tags(Name) ->
55  
-	case request("https://github.com/api/v2/json/repos/show/" ++ proper_repo_name(Name) ++  "/tags") of
56  
-		{struct, Object} ->
57  
-			{struct, Tags} = proplists:get_value(<<"tags">>, Object),
58  
-			lists:map(fun({Tag, SHA1}) ->
59  
-							  {binary_to_list(Tag),
60  
-							   binary_to_list(SHA1)}
61  
-					  end, Tags)
62  
-	end.
  55
+    {ok, RepoServer} = agner_repo_server:create(Name, {flavour, "master"}),
  56
+    ok = agner_repo_server:clone(RepoServer, fun (N) -> "git://github.com/" ++ proper_repo_name(N) ++ ".git" end),
  57
+    Path = agner_repo_server:file(RepoServer, []),
  58
+    Port = agner_download:git(["tag", "-l"], [{cd, Path}, use_stdio, stderr_to_stdout, {line, 255}]),
  59
+    PortHandler = fun (F,Acc) ->
  60
+                          receive
  61
+                              {'EXIT', Port, _} ->
  62
+                                  error;
  63
+                              {Port,{exit_status,0}} ->
  64
+                                  {ok, Acc};
  65
+                              {Port,{exit_status,_}} ->
  66
+                                  error;
  67
+                              {Port, {data, {_, D}}} when is_list(D) ->
  68
+                                  Tag = string:strip(D, right, $\n),
  69
+                                  F(F,[Tag|Acc]);
  70
+                              _ ->
  71
+                                  F(F,Acc)
  72
+                          end
  73
+                  end,
  74
+    Result = PortHandler(PortHandler,[]),
  75
+    case Result of
  76
+        error ->
  77
+            [];
  78
+        {ok, Tags} ->
  79
+            lists:map(fun (Tag) ->
  80
+                              RevParsePort = agner_download:git(["rev-parse",Tag], 
  81
+                                                                [{cd, Path}, use_stdio, stderr_to_stdout, {line, 255}]),
  82
+                              RevParsePortHandler = fun (F1,Acc1) ->
  83
+                                                            receive 
  84
+                                                                {'EXIT', RevParsePort, _} ->
  85
+                                                                    "";
  86
+                                                                {RevParsePort,{exit_status,0}} ->
  87
+                                                                    Acc1;
  88
+                                                                {RevParsePort, {exit_status, _}} ->
  89
+                                                                    "";
  90
+                                                                {RevParsePort, {data, {_, D1}}} when is_list (D1) ->
  91
+                                                                    F1(F1,D1);
  92
+                                                                _ ->
  93
+                                                                    F1(F1,Acc1)
  94
+                                                            end
  95
+                                                    end,
  96
+                              SHA1 = RevParsePortHandler(RevParsePortHandler,""),
  97
+                              {Tag, SHA1}
  98
+                      end, Tags)
  99
+    end.
63 100
 
64 101
 
65 102
 branches(Name) ->
66  
-	case request("https://github.com/api/v2/json/repos/show/" ++ proper_repo_name(Name) ++  "/branches") of
67  
-		{error, _Reason} = Error ->
68  
-			Error;
69  
-		{struct, Object} ->
70  
-			{struct, Branches} = proplists:get_value(<<"branches">>, Object),
71  
-			lists:map(fun({Branch, SHA1}) ->
72  
-							  {binary_to_list(Branch),
73  
-							   binary_to_list(SHA1)}
74  
-					  end, Branches)
75  
-	end.
  103
+    {ok, RepoServer} = agner_repo_server:create(Name, {flavour, "master"}),
  104
+    ok = agner_repo_server:clone(RepoServer, fun (N) -> "git://github.com/" ++ proper_repo_name(N) ++ ".git" end),
  105
+    Path = agner_repo_server:file(RepoServer, []),
  106
+    Port = agner_download:git(["branch", "-r"], [{cd, Path}, use_stdio, stderr_to_stdout, {line, 255}]),
  107
+    PortHandler = fun (F,Acc) ->
  108
+                          receive
  109
+                              {'EXIT', Port, _} ->
  110
+                                  error;
  111
+                              {Port,{exit_status,0}} ->
  112
+                                  {ok, Acc};
  113
+                              {Port,{exit_status,_}} ->
  114
+                                  error;
  115
+                              {Port, {data, {_, "  origin/HEAD" ++ _}}} -> %% ignore
  116
+                                  F(F, Acc);
  117
+                              {Port, {data, {_, "  origin/" ++ Branch}}} when is_list(Branch) ->
  118
+                                  F(F,[Branch|Acc]);
  119
+                              {Port, {data, {_, _}}} -> %% ignore as well
  120
+                                  F(F,Acc);
  121
+                              _ ->
  122
+                                  F(F,Acc)
  123
+                          end
  124
+                  end,
  125
+    Result = PortHandler(PortHandler,[]),
  126
+    case Result of
  127
+        error ->
  128
+            [];
  129
+        {ok, Branches} ->
  130
+            lists:map(fun (Branch) ->
  131
+                              RevParsePort = agner_download:git(["rev-parse",Branch], 
  132
+                                                                [{cd, Path}, use_stdio, stderr_to_stdout, {line, 255}]),
  133
+                              RevParsePortHandler = fun (F1,Acc1) ->
  134
+                                                            receive 
  135
+                                                                {'EXIT', RevParsePort, _} ->
  136
+                                                                    "";
  137
+                                                                {RevParsePort,{exit_status,0}} ->
  138
+                                                                    Acc1;
  139
+                                                                {RevParsePort, {exit_status, _}} ->
  140
+                                                                    "";
  141
+                                                                {RevParsePort, {data, {_, D1}}} when is_list (D1) ->
  142
+                                                                    F1(F1,D1);
  143
+                                                                _ ->
  144
+                                                                    F1(F1,Acc1)
  145
+                                                            end
  146
+                                                    end,
  147
+                              SHA1 = RevParsePortHandler(RevParsePortHandler,""),
  148
+                              {Branch, SHA1}
  149
+                      end, Branches)
  150
+    end.
76 151
 
77 152
 spec(Name, Version) ->
78 153
     {ok, RepoServer} = agner_repo_server:create(Name, Version),

0 notes on commit 04d4cfb

Please sign in to comment.
Something went wrong with that request. Please try again.