|
77 | 77 | -type result() :: ok | {ok, term()} | {error, term()}.
|
78 | 78 |
|
79 | 79 | -define(GITHUB_API, "https://api.github.com").
|
| 80 | +-define(MAX_DESCRIPTION_LENGTH, 140). |
80 | 81 |
|
81 | 82 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
82 | 83 | %% Public API
|
@@ -434,8 +435,9 @@ remove_collaborator(Cred, Repo, Collaborator) ->
|
434 | 435 | result().
|
435 | 436 | create_status(Cred, Repo, Sha, State, Description, Context) ->
|
436 | 437 | Url = make_url(new_status, {Repo, Sha}),
|
| 438 | + FormatDescription = format_description(Description), |
437 | 439 | Data = #{<<"state">> => State,
|
438 |
| - <<"description">> => list_to_binary(Description), |
| 440 | + <<"description">> => list_to_binary(FormatDescription), |
439 | 441 | <<"context">> => list_to_binary(Context)
|
440 | 442 | },
|
441 | 443 | Body = egithub_json:encode(Data),
|
@@ -480,6 +482,17 @@ combined_status(Cred, Repo, Ref) ->
|
480 | 482 | %% Private Functions
|
481 | 483 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
482 | 484 |
|
| 485 | +%doc format_description format the description to avoid error 422 |
| 486 | +%doc The message submitted is longer that the maximum length of 140 characters |
| 487 | +-spec format_description(string()) -> string(). |
| 488 | +format_description(Description) -> |
| 489 | + case length(Description) of |
| 490 | + Size when Size >= ?MAX_DESCRIPTION_LENGTH -> |
| 491 | + %% to be continued. |
| 492 | + string:sub_string(Description, 1, ?MAX_DESCRIPTION_LENGTH - 3) ++ "..."; |
| 493 | + Size when Size < ?MAX_DESCRIPTION_LENGTH -> Description |
| 494 | + end. |
| 495 | + |
483 | 496 | %% Create Status
|
484 | 497 | make_url(new_status, {Repo, Sha}) ->
|
485 | 498 | Url = ?GITHUB_API ++ "/repos/~s/statuses/~s",
|
|
0 commit comments