Current section

28 Versions

Jump to

Compare versions

3 files changed
+30 additions
-3 deletions
  @@ -35,4 +35,4 @@
35 35 {<<"name">>,<<"inch_ex">>},
36 36 {<<"optional">>,false},
37 37 {<<"requirement">>,<<"~> 0.5">>}]]}.
38 - {<<"version">>,<<"0.0.2">>}.
38 + {<<"version">>,<<"0.0.3">>}.
  @@ -28,11 +28,38 @@ defmodule Analyze.BuildStatus do
28 28
29 29 defp repo_status_authorization do
30 30 case Application.get_env(:analyze, :status_authorization) do
31 - nil -> []
31 + nil -> repo_status_oauth()
32 32 auth -> [{"Authorization", "Basic " <> auth}]
33 33 end
34 34 end
35 35
36 + defp repo_status_oauth do
37 + case Application.get_env(:analyze, :status_refresh_token) do
38 + nil -> []
39 + {id, token} ->
40 + headers =
41 + [
42 + {"Content-Type", "application/x-www-form-urlencoded"},
43 + {"Authorization", "Basic " <> Base.encode64(id)},
44 + ]
45 +
46 + body =
47 + %{
48 + grant_type: "refresh_token",
49 + refresh_token: token
50 + }
51 + |> URI.encode_query
52 +
53 + case :hackney.request(:POST, "https://bitbucket.org/site/oauth2/access_token", headers, body, @options) do
54 + {:ok, 200, _, auth_json} ->
55 + auth = Poison.decode!(auth_json)
56 +
57 + [{"Authorization", "Bearer " <> auth["access_token"]}]
58 + 5 -> []
59 + end
60 + end
61 + end
62 +
36 63 defp repo_status_url do
37 64 case Application.get_env(:analyze, :status_endpoint) do
38 65 nil -> nil
  @@ -6,7 +6,7 @@ defmodule Analyze.Mixfile do
6 6 app: :analyze,
7 7 description: "Mix task to analyze and report Elixir code.",
8 8 # escript: [main_module: Analyze],
9 - version: "0.0.2",
9 + version: "0.0.3",
10 10 elixir: "~> 1.4",
11 11 build_embedded: Mix.env == :prod,
12 12 start_permanent: Mix.env == :prod,