Permalink
Browse files

Update repo_server to use username and password from config

  • Loading branch information...
1 parent d611f40 commit 394f660181f7031249522992e216fe035b0e1e61 @rambocoder committed Mar 19, 2013
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -0,0 +1,7 @@
+# Stream all events on GitHub that happen to repos containing Erlang code
+
+Visit [ErlangHub.com](http://erlanghub.com) for demo.
+
+# TODO:
+* Make it pretty
+* Add ability to maintain repos via the web
View
Binary file not shown.
View
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
- <title>Erlanghub Events</title>
+ <title>ErlangHub Events</title>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico">
<style>
html, body {margin:0; padding:0;}
@@ -10,7 +10,9 @@
border-radius: 15px; border:2px solid #000; }
#header {text-align:center; }
/* Messages Display Area */
- #Events {margin:0 auto; margin-bottom: 20px; border:1px solid #CCC; width:90%; height:16em; overflow:auto;
+ #Events {margin:0 auto; margin-bottom: 20px; border:1px solid #CCC; width:90%;
+ min-height:16em;
+ overflow:auto;
background-color: #F8F8F8; }
#msgList {margin:0px; padding:5px; list-style:none;}
#msgList li {padding:5px 10px; border-bottom:1px solid gray;}
View
@@ -32,7 +32,8 @@ $(function () {
// work with value
msg = value.replace("\\", "");
obj = JSON.parse(msg);
- $("#msgList").prepend('<li>' + obj.type + " in " + obj.repo.name + " by: " + obj.actor.login + '</li>');
+ var date = new Date(obj.created_at);
+ $("#msgList").prepend('<li>' + date.toString().replace(/GMT.*/g,"") + " " + obj.type + ' in <a href="https://github.com/' + obj.repo.name + '" target="_blank">' + obj.repo.name + '</a> by: <a href="https://github.com/' + obj.actor.login + '" target="_blank">' + obj.actor.login +'</a></li>');
//$.getJSON(obj.repo.url, function (data) {
// $("#msgList").prepend('<li>' + obj.type + " : " + data.name + " @ <a href='" + data.html_url + "'>" + obj.repo.name + "</a> Language: " + data.language + '</li>');
//});
@@ -44,6 +45,7 @@ $(function () {
}
};
+
$('#Events').bind({
'pull': function () {
$.ajax({
@@ -76,8 +78,19 @@ $(function () {
setTimeout(function () { /* Do Nothing here */
}, 1);
}
- }).triggerHandler("pull"); // kick off the pull event after all the events are bound to the Events object
+ });
+ $('#Events').bind({
+ 'start' : function() {
+ $.getJSON(pullUrl, function (data) {
+ // data.timestamp is in microseconds
+ // let's get the last 5 minutes of changes
+ var subtract = 5 * 60 * 1000000;
+ timestamp = data.timestamp - subtract;
+ // kick off the pull event after we get the last timestamp
+ $('#Events').triggerHandler("pull");
+ });
+ }}).triggerHandler("start");
});
@@ -34,7 +34,7 @@ since(<<"GET">>, Since, Req) ->
end,
Json = jiffy:encode({[{timestamp, Timestamp}, {messages, Messages}, {timeout, Timeout}]}),
cowboy_req:reply(200,
- [{<<"Content-Encoding">>, <<"utf-8">>}, {<<"content-type">>, <<"application/json">>}], Json, Req);
+ [{<<"content-encoding">>, <<"utf-8">>}, {<<"content-type">>, <<"application/json">>}], Json, Req);
since(_, _, Req) ->
%% Method not allowed.
cowboy_req:reply(405, Req).
View
@@ -43,7 +43,7 @@ handle_info(trigger, Cache) ->
NewCache = Cache;
Events ->
NewCache = lists:foldl(fun (Event, Acc) -> insert_event(Event, Acc) end, Cache, lists:reverse(Events)),
- io:format("Received Events from github:~n", []),
+ io:format("Received Events from github~n", []),
% ok = file:write_file("output.txt", Body1, [write, append]),
RemainingHits = proplists:get_value("x-ratelimit-remaining", Headers1),
io:format("Remaining hits: ~p ~n", [RemainingHits])
View
@@ -53,10 +53,13 @@ code_change(_OldVsn, State, _Extra) ->
fetch_language_info({RepoId, RepoUrl}) ->
+
+ {ok, Username} = application:get_env(erlanghub, username),
+ {ok, Password} = application:get_env(erlanghub, password),
LanguageUrl = string:concat(unicode:characters_to_list(RepoUrl), "/languages"),
- case httpc:request(get, {LanguageUrl, []}, [{timeout, 10000}], []) of
+ case httpc:request(get, {LanguageUrl, [auth_header(Username, Password)]}, [{timeout, 10000}], []) of
{error, Reason} -> io:format("Repo error:~p~n", [Reason]);
- {ok, {{_Version, StatusCode, _Reason}, _Headers1, Body1}} ->
+ {ok, {{_Version, StatusCode, Reason}, _Headers1, Body1}} ->
case StatusCode of
200 ->
{Languages} = jiffy:decode(Body1),
@@ -72,9 +75,13 @@ fetch_language_info({RepoId, RepoUrl}) ->
Body1,
httpd_util:rfc1123_date(erlang:localtime()),
IsErlang]);
- _ -> nothing
+ _ -> io:format("StatusCode:~p Reason:~p RepoId: ~p RepoUrl:~p~n", [StatusCode, Reason, RepoId, RepoUrl])
end
end,
% io:format("Language URL: ~p~n", [LanguageUrl]),
% io:format("Repo id: ~p~n", [RepoId]),
timer:sleep(100).
+
+auth_header(User, Pass) ->
+ Encoded = base64:encode_to_string(lists:append([erlang:atom_to_list(User),":",erlang:atom_to_list(Pass)])),
+ {"Authorization","Basic " ++ Encoded}.

0 comments on commit 394f660

Please sign in to comment.