Skip to content

Commit

Permalink
Add introspect script to compare what we currently point to versus th…
Browse files Browse the repository at this point in the history
…e latest for all deps
  • Loading branch information
rnewson committed Sep 24, 2015
1 parent a3bdfc6 commit 75e54ea
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,8 @@ ifeq ($(with_fauxton), 1)
@echo "Building Fauxton"
@cd src/fauxton && npm install && ./node_modules/grunt-cli/bin/grunt couchdb
endif

.PHONY: introspect
introspect:
rebar -r update-deps
./introspect
73 changes: 73 additions & 0 deletions introspect
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env escript
%% -*- mode: erlang -*-

main(_) ->
introspect("rebar.config.script").

introspect(File) ->
Bindings = [{'SCRIPT', File}, {'CONFIG', []}],
{ok, Config} = file:script(File, Bindings),
{deps, Deps} = lists:keyfind(deps, 1, Config),
introspect_deps(Deps).

introspect_deps([]) ->
ok;
introspect_deps([Dep | Rest]) ->
introspect_dep(Dep),
introspect_deps(Rest).

introspect_dep({App, VsnRegex, {git, Url, From}, _Raw}) ->
introspect_dep({App, VsnRegex, {git, Url, From}});
introspect_dep({App, _VsnRegex, {git, _Url, From}}) ->
io:format(bold("~s~n"), [App]),
introspect_diff(App, From),
io:format("~n", []),
ok.

revision({branch, Branch}) ->
Branch;
revision({tag, Tag}) ->
Tag;
revision(Rev) ->
Rev.

introspect_diff(App, From) ->
introspect_diff(App, revision(From), "origin/master").

introspect_diff(App, From, ToBranch) ->
{ok, Log} = sh(App, io_lib:format("git log --pretty=oneline ~s..~s", [From, ToBranch])),
case Log of
[] ->
io:format(" up to date on ~s~n", [bold(ToBranch)]);
_ ->
io:format(" ~B commits behind ~s~n", [length(Log), bold(ToBranch)]),
io:format("~s~n~n", [string:join([" " ++ L || L <- Log], "\n")])
end.

sh(App, Cmd) ->
Dir = lists:flatten(["src/", atom_to_list(App)]),
Port = open_port({spawn, lists:flatten(Cmd)},
[{cd, Dir},
{line, 16384},
exit_status,
stderr_to_stdout,
use_stdio]),
read_port(Port).

read_port(Port) ->
read_port(Port, []).

read_port(Port, Acc) ->
receive
{Port, {data, {eol, Line}}} ->
read_port(Port, [Line | Acc]);
{Port, {data, {noeol, Line}}} ->
read_port(Port, [Line | Acc]);
{Port, {exit_status, 0}} ->
{ok, lists:reverse(Acc)};
{Port, {exit_status, Code}} ->
{error, Code, Acc}
end.

bold(Text) ->
"\e[1m" ++ Text ++ "\e[0m".

0 comments on commit 75e54ea

Please sign in to comment.