Skip to content

Commit

Permalink
update_reference: required params are funargs
Browse files Browse the repository at this point in the history
  • Loading branch information
Minoru committed Nov 6, 2016
1 parent ee9006f commit 957771a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
9 changes: 2 additions & 7 deletions README.md
Expand Up @@ -254,15 +254,10 @@ octo:create_tag(Owner, Repo, TagName, Source).
%% - RefName: Name of the to be created tag. Char list.
%% - Valid examples: refs/heads/my-branch, heads/my-branch, refs/tags/my-tag, tags/my-tag
%% - Invalid examples: my-branch, my-tag
%% - Payload: Meta information about the to be updated reference. Tuple of tuples.
%% Example:
%% {
%% {<<"sha">>, <<"aa218f56b14c9653891f9e74264a383fa43fefbd">>},
%% {<<"force">>, true|false}
%% }
%% - Sha: The SHA1 value to set this reference to. Char list or binary.
%%
%% Returns the just updated branch octo_reference.
octo:update_reference(Owner, Repo, RefName, Payload).
octo:update_reference(Owner, Repo, RefName, Sha).

%% Delete a specific reference of a repository.
%%
Expand Down
8 changes: 4 additions & 4 deletions src/octo.erl
Expand Up @@ -168,10 +168,10 @@ create_tag(Owner, Repo, TagName, Source) ->
create_tag(Owner, Repo, TagName, Source, Options) ->
exec(octo_reference, create_tag, [Owner, Repo, TagName, Source, Options]).

update_reference(Owner, Repo, RefName, Payload) ->
update_reference(Owner, Repo, RefName, Payload, []).
update_reference(Owner, Repo, RefName, Payload, Options) ->
exec(octo_reference, update, [Owner, Repo, RefName, Payload, Options]).
update_reference(Owner, Repo, RefName, Sha) ->
update_reference(Owner, Repo, RefName, Sha, []).
update_reference(Owner, Repo, RefName, Sha, Options) ->
exec(octo_reference, update, [Owner, Repo, RefName, Sha, Options]).

delete_reference(Owner, Repo, RefName) ->
delete_reference(Owner, Repo, RefName, []).
Expand Down
10 changes: 7 additions & 3 deletions src/octo_reference.erl
Expand Up @@ -68,10 +68,14 @@ create_branch(Owner, Repo, BranchName, Source, Options) ->
create_tag(Owner, Repo, TagName, Source, Options) ->
create(Owner, Repo, "refs/tags/" ++ TagName, Source, Options).

update(Owner, Repo, "refs/" ++ RefName, Payload, Options) ->
update(Owner, Repo, RefName, Payload, Options);
update(Owner, Repo, RefName, Payload, Options) ->
update(Owner, Repo, "refs/" ++ RefName, Sha, Options) ->
update(Owner, Repo, RefName, Sha, Options);
update(Owner, Repo, RefName, Sha, Options) ->
Url = octo_url_helper:reference_url(Owner, Repo, RefName),
ShaBinary = octo_binary_helper:ensure_binary(Sha),
Payload = {
{<<"sha">>, ShaBinary}
},
PayloadJson = jsonerl:encode(Payload),
case octo_http_helper:patch(Url, Options, PayloadJson) of
{ok, Result} -> {ok, ?json_to_record(octo_reference, Result)};
Expand Down
4 changes: 2 additions & 2 deletions test/octo_test.erl
Expand Up @@ -215,7 +215,7 @@ error_passthrough_test_() ->
{update_reference, ["octocat",
"Hello-World",
"refs/heads/featureA",
undefined]}]]).
"aa218f56b14c9653891f9e74264a383fa43fefbd"]}]]).

create_pull_request_test_() ->
{ok, PRJson} = file:read_file(?ASSETS_DIR"pull_request_create_response.json"),
Expand Down Expand Up @@ -519,7 +519,7 @@ update_reference_test_() ->
{ok, Result} = octo:update_reference("octocat",
"Hello-World",
"refs/heads/featureA",
undefined),
"aa218f56b14c9653891f9e74264a383fa43fefbd"),

?assertEqual(Expected, Result),

Expand Down

0 comments on commit 957771a

Please sign in to comment.