diff --git a/README.md b/README.md index 3e15ceb..239e571 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ Prepares a merge request description, with link to Jira ticket and current branc git mr [OPTIONS] menu [SEARCH_TERM] git mr [OPTIONS] menu update [--current] [SEARCH_TERM] +git mr [OPTIONS] menu edit [SEARCH_TERM] git mr [OPTIONS] menu status [SEARCH_TERM] git mr [OPTIONS] (ip|cr|qa|ok) [BRANCH] @@ -393,6 +394,7 @@ This view allows navigating through the merge request commits, and comments left
 git mr [OPTION...] menu                       [SEARCH_TERM] 
 git mr [OPTION...] menu up|update [--current] [SEARCH_TERM] 
+git mr [OPTION...] menu ed|edit               [SEARCH_TERM] 
 git mr [OPTION...] menu st|status             [SEARCH_TERM] 
 
@@ -411,6 +413,16 @@ Searches for all (non-closed) merge requests with the current issue code in the * `git mr menu up|update --current` Inserts or updates menu in current merge request description only (prompts for confirmation). +* `git mr menu ed|edit` + Opens menu in editor for tweaking before updating related merge request descriptions. + Uses default editor, guessed through `VISUAL` or `EDITOR` environment variables. + + ![git mr menu edit](doc/git-mr-menu-edit-0.png) + + ![git mr menu edit](doc/git-mr-menu-edit-1.png) + + ![git mr menu edit](doc/git-mr-menu-edit-2.png) + * `git mr menu st|status` Prints menu and status indicators for every related merge request. diff --git a/completion/_git-mr b/completion/_git-mr index 6f55953..840337c 100644 --- a/completion/_git-mr +++ b/completion/_git-mr @@ -36,6 +36,7 @@ __git-mr_menu_commands() { local -a commands=( 'status:show menu merge requests status summary' 'update:update menu in related merge request descriptions' + 'edit:edit menu before updating in related merge request descriptions' ) _describe -V -t mr-menu-commands 'mr menu commands' commands } @@ -61,6 +62,7 @@ _git-mr() { op|open) mr_action="open" ;; st|status) [[ $mr_action == "menu" ]] && mr_action="menu-status" || mr_action="status" ;; up|update) [[ $mr_action == "menu" ]] && mr_action="menu-update" || mr_action="update" ;; + ed|edit) [[ $mr_action == "menu" ]] && mr_action="menu-edit" || mr_action="default" ;; mg|merge) mr_action="merge" ;; menu) mr_action="menu" ;; ip|cr|qa|ok) mr_action="transition" ;; @@ -89,7 +91,7 @@ _git-mr() { '(--no-color)'--no-color'[disable terminal colors]' '(--no-links)'--no-links'[disable terminal hyperlinks]' );; esac - case $mr_action in default|update|menu-update|transition|merge) opts+=( + case $mr_action in default|update|menu-update|menu-edit|transition|merge) opts+=( '(-y --yes)'{-y,--yes}'[bypass confirmation prompts ("yes")]' );; esac opts+=( diff --git a/doc/generate-sample-output.sh b/doc/generate-sample-output.sh index 2fe7636..48a648e 100755 --- a/doc/generate-sample-output.sh +++ b/doc/generate-sample-output.sh @@ -422,6 +422,51 @@ EOF echo } +sample_mr_menu_edit() { + fake_prompt "git mr menu edit" + + mr_description="# [XY-1234 Quisque sed](https://jira.example.net/browse/XY-1234) + +## Menu + +### Feature + +Lorem ipsum feature + +* Some Project: [Feature/XY-1234 Lorem Ipsum](https://myapp.gitlab.com/some/project/...) +* **Other Project: [Feature/XY-1234 Quisque sed](https://myapp.gitlab.com/other/project/...)** + +### Documentation + +* Third Project: [Feature/XY-1234 Nunc vestibulum](https://myapp.gitlab.com/third/project/...) + +-------------------------------------------------------------------------------- + + +Quisque sed consectetur adipiscing elit. + +Pellentesque eu lectus felis. Phasellus maximus, quam quis accumsan varius, +enim nunc egestas ante, ut venenatis nunc eros non lorem. Ut molestie elementum +nisi in sollicitudin. +" + +mr_url="https://myapp.gitlab.com/other/project/..." +mr_title="Feature/XY-1234 Quisque sed" +project_name="Other Project" + + cat < + + + + + + + + + +EOF +} + mr_menu_print_title() { local issue_code=$1 local issue_title=$2 @@ -1821,7 +1887,7 @@ mr_menu_update() { ')" local mr_menu_content; mr_menu_content=$(mr_menu_contents "$menu_items" "$mr_url") - local updated_description; updated_description="$(mr_menu_replace_description "$mr_description" "$mr_menu_content")" + local updated_description; updated_description="$(mr_menu_replace_description "$mr_description" "$mr_menu_content" | tr -d '\r')" mr_menu_print_description "$updated_description" "$mr_url" "$mr_title" @@ -1869,16 +1935,127 @@ mr_menu_update_all() { ')" project_url=$(gitlab_extract_project_url_part "$mr_url") - [[ -n $project_name && $project_name != "null" ]] || project_name="$project_url" # Fallback to URL portion # Load existing merge request details merge_request=$(gitlab_merge_request "$mr_iid" "$project_url") - mr_description=$(gitlab_extract_description "$merge_request") mr_menu_content=$(mr_menu_contents "$menu_items" "$mr_url") - updated_description="$(mr_menu_replace_description "$mr_description" "$mr_menu_content")" + updated_description="$(mr_menu_replace_description "$mr_description" "$mr_menu_content" | tr -d '\r')" + + clear_screen + mr_menu_print_title "$issue_code" "" "" "$menu_items" "$i" + mr_menu_print_description "$updated_description" "$mr_url" "$mr_title" "$project_name" + + mr_update_data='{}' + if confirm "Do you want to update the menu in the merge request description?"; then + mr_update_data=$(jq_build "description" "$updated_description" "$mr_update_data") || exit "$ERR_MR" + fi + if [[ $mr_update_data != "{}" ]]; then + echo -n "Updating merge request..." + result=$(gitlab_merge_request_update "$mr_iid" "$mr_update_data" "$project_url") + [[ -n $result ]] && + ((updated_count += 1)) && + echo -e "OK\n" + else + echo + fi + ((i += 1)) + done + + [[ $updated_count -gt 0 ]] && + echo "${updated_count} merge request$([[ $updated_count -gt 1 ]] && echo 's') updated" +} + +mr_menu_highlight_current() { + local menu_content=$1 + local mr_url=$2 + + local search replace + search="(\s?)\* (.*\[.*\]\($(regex_escape "$mr_url")\).*)" + replace="\1* ${MD_BOLD}\2${MD_BOLD}" + + echo "$menu_content" | sed -r -e "s/${search}/${replace}/" +} + +mr_menu_edit_read_file() { + local menu_file=$1 + + # Cleanup edited menu contents: + # - remove comment lines and sections + # - remove leading blank lines and collapse multiple blank lines + local edited_content; edited_content=$( \ + sed -e '//d' -e '//d' "$menu_file" | + sed -e '/./,$!d' -e '/^$/N;/^\n$/D' \ + ) + + # Abort if menu is empty + [[ -z "${edited_content// /}" ]] && return + + # Output menu contents + echo -e "${GIT_MR_MENU_START}\n" + echo -e "${edited_content}\n" + echo -e "${GIT_MR_MENU_END}" +} + +mr_menu_edit() { + local issue_code=$1 + local menu_items=$2 + + # Determine editor + local editor; editor=$(git_mr_editor) || exit $? + + # Init temporary menu file + local menu_file; menu_file="$(git rev-parse --git-dir)/MR_MENU_EDITMSG.md" + mr_menu_editable_content "$menu_items" > "$menu_file" + + # Open temporary menu file in editor + "$editor" "$menu_file" + + # Get file contents + local edited_content; edited_content="$(mr_menu_edit_read_file "$menu_file")" + + # Abort if menu is empty + [[ -z "$edited_content" ]] && exit_error 0 "Empty menu, aborting." + + local mr_iid \ + mr_url \ + mr_title \ + project_name \ + project_url \ + merge_request \ + mr_description \ + mr_menu_content \ + updated_description \ + mr_update_data \ + result + + # Use array instead of looping over variable content with `read` to leave standard input open for `confirm` + local menu_array + readarray menu_array < <(echo "$menu_items") + + # Iterate over menu merge requests + local i=1 updated_count=0 + for menu_item in "${menu_array[@]}"; do + + eval "$(echo "$menu_item" | jq -r ' + "mr_iid=" + (.iid | @sh) + ";\n" + + "mr_url=" + (.web_url | @sh) + ";\n" + + "mr_title=" + (.title | @sh) + ";\n" + + "project_name=" + (.project_name | @sh) + ";\n" + ')" + + project_url=$(gitlab_extract_project_url_part "$mr_url") + [[ -n $project_name && $project_name != "null" ]] || project_name="$project_url" # Fallback to URL portion + + # Load existing merge request details + merge_request=$(gitlab_merge_request "$mr_iid" "$project_url") + mr_description=$(gitlab_extract_description "$merge_request") + + # Prepare menu content + mr_menu_content="$(mr_menu_highlight_current "$edited_content" "$mr_url")" + updated_description="$(mr_menu_replace_description "$mr_description" "$mr_menu_content" | tr -d '\r')" clear_screen mr_menu_print_title "$issue_code" "" "" "$menu_items" "$i" @@ -1902,6 +2079,8 @@ mr_menu_update_all() { [[ $updated_count -gt 0 ]] && echo "${updated_count} merge request$([[ $updated_count -gt 1 ]] && echo 's') updated" + + rm "$menu_file" } mr_menu_start_line() { @@ -1944,7 +2123,6 @@ mr_menu_replace_description() { else # replace menu once if [[ $i -eq "$menu_end" ]]; then - echo_debug "Replacing menu" echo "$menu_content" menu_was_output=1 fi @@ -1954,7 +2132,6 @@ mr_menu_replace_description() { echo "$mr_description_line" # insert menu once if [[ $menu_was_output -eq 0 && -z "$mr_description_line" && $i -gt 1 ]]; then - echo_debug "Inserting menu" echo "$menu_content" echo menu_was_output=1 @@ -1963,10 +2140,9 @@ mr_menu_replace_description() { prev_description_line="$mr_description_line" ((i += 1)) - done < <(echo "$mr_description") + done < <(echo "$mr_description" | tr -d '\r') if [[ $menu_was_output -eq 0 ]]; then - echo_debug "Inserting menu (failsafe)" [[ -n "$prev_description_line" ]] && echo echo "$menu_content" fi @@ -2573,6 +2749,7 @@ mr_menu() { # Consume options up|update) git_mr_menu_mode=update ;; --current) git_mr_menu_update_all=0 ;; + ed|edit) git_mr_menu_mode=edit ;; st|status) git_mr_menu_mode=status ;; # Default: conserve argument *) args+=("${1}") ;; @@ -2599,6 +2776,7 @@ mr_menu() { update) if [[ $git_mr_menu_update_all -eq 1 ]] then mr_menu_update_all "$issue_code" "$menu_items" else mr_menu_update "$menu_items"; fi ;; + edit) mr_menu_edit "$issue_code" "$menu_items" ;; status) mr_menu_status "$issue_code" "$menu_items" ;; *) return "$ERR_MR" ;; esac @@ -2724,6 +2902,7 @@ ${b}SYNOPSIS${r} ${u}git${r} ${u}mr${r} [OPTION...] merge [BRANCH] ${u}git${r} ${u}mr${r} [OPTION...] menu [SEARCH_TERM] + ${u}git${r} ${u}mr${r} [OPTION...] menu edit [SEARCH_TERM] ${u}git${r} ${u}mr${r} [OPTION...] menu update [--current] [SEARCH_TERM] ${u}git${r} ${u}mr${r} [OPTION...] menu status [SEARCH_TERM] diff --git a/git-mr-completion.bash b/git-mr-completion.bash index 634c344..820fcaf 100644 --- a/git-mr-completion.bash +++ b/git-mr-completion.bash @@ -35,6 +35,7 @@ __git-mr_menu_commands() { cat <<-'ACTIONS' status update + edit ACTIONS )" } @@ -55,6 +56,7 @@ _git_mr() { open) mr_action="open" ;; status) [[ $mr_action == "menu" ]] && mr_action="menu-status" || mr_action="status" ;; update) [[ $mr_action == "menu" ]] && mr_action="menu-update" || mr_action="update" ;; + edit) [[ $mr_action == "menu" ]] && mr_action="menu-edit" || mr_action="default" ;; merge) mr_action="merge" ;; menu) mr_action="menu" ;; ip | cr | qa | ok) mr_action="transition" ;; @@ -70,6 +72,7 @@ _git_mr() { op) mr_action="open" ;; st) [[ $mr_action == "menu" ]] && mr_action="menu-status" || mr_action="status" ;; up) [[ $mr_action == "menu" ]] && mr_action="menu-update" || mr_action="update" ;; + ed) [[ $mr_action == "menu" ]] && mr_action="menu-edit" || mr_action="default" ;; mg) mr_action="merge" ;; esac fi @@ -92,7 +95,7 @@ _git_mr() { __gitcomp_nl_append '--no-color' __gitcomp_nl_append '--no-links' ;; esac - case $mr_action in default | update | menu-update | transition | merge) + case $mr_action in default | update | menu-update | menu-edit | transition | merge) __gitcomp_nl_append '-y'; __gitcomp_nl_append '--yes' ;; esac __gitcomp_nl_append '-v'; __gitcomp_nl_append '--verbose' diff --git a/test/fake-menu-edit-empty.sh b/test/fake-menu-edit-empty.sh new file mode 100755 index 0000000..59d2ec1 --- /dev/null +++ b/test/fake-menu-edit-empty.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +test_menu_file="$(git rev-parse --git-dir)/MR_MENU_EDITMSG.md" + +echo ' + + + + + + + + + + + + + + + +' > "$test_menu_file" diff --git a/test/fake-menu-edit.sh b/test/fake-menu-edit.sh new file mode 100755 index 0000000..4a66aeb --- /dev/null +++ b/test/fake-menu-edit.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +test_menu_file="$(git rev-parse --git-dir)/MR_MENU_EDITMSG.md" + +echo ' + + +* Fake edited menu +* For test + + + + + + + + + + + + + + +' > "$test_menu_file" diff --git a/test/git-mr.bats b/test/git-mr.bats index 5f2f044..fe90626 100644 --- a/test/git-mr.bats +++ b/test/git-mr.bats @@ -150,16 +150,6 @@ sha_link() { assert_failure "$ERR_GIT_REPO" } -@test "Uses GNU commands" { - run sed --version - assert_success - assert_output --partial "GNU sed" - - run grep --version - assert_success - assert_output --partial "GNU grep" -} - @test "Determines current branch" { git switch main run git_current_branch @@ -385,6 +375,16 @@ sha_link() { ################################################################################ # Misc. utilities +@test "Uses GNU commands" { + run sed --version + assert_success + assert_output --partial "GNU sed" + + run grep --version + assert_success + assert_output --partial "GNU grep" +} + @test "Exits with error" { run exit_error 99 "Nope!" assert_failure 99 @@ -527,6 +527,20 @@ sha_link() { assert_success } +@test "Determines default text editor from env" { + VISUAL=fake_visual_test + EDITOR=fake_editor_test + run git_mr_editor + assert_failure + assert_output "Invalid editor: fake_visual_test" + + VISUAL= + EDITOR=fake_editor_test + run git_mr_editor + assert_failure + assert_output "Invalid editor: fake_editor_test" +} + ################################################################################ # Markdown formatting @@ -2110,6 +2124,33 @@ End" )" } +@test "Builds editable menu content" { + test_menu_items='{"iid":31,"title":"MR 31 title","web_url":"https://gitlab.example.net/proj-C/-/merge_requests/31","state":"opened","project_id":3,"project_name":"Project C"} +{"iid":11,"title":"MR 11 title","web_url":"https://gitlab.example.net/proj-A/-/merge_requests/11","state":"opened","project_id":1,"project_name":"Project A"} +{"iid":21,"title":"MR 21 title","web_url":"https://gitlab.example.net/proj-B/-/merge_requests/21","state":"opened","project_id":2,"project_name":"Project B"}' + + run mr_menu_editable_content "$test_menu_items" + assert_output "$(cat <<- EOF + + * Project C: [MR 31 title](https://gitlab.example.net/proj-C/-/merge_requests/31) + * Project A: [MR 11 title](https://gitlab.example.net/proj-A/-/merge_requests/11) + * Project B: [MR 21 title](https://gitlab.example.net/proj-B/-/merge_requests/21) + + + + + + + + + + + + + EOF + )" +} + @test "Prints menu title" { run mr_menu_print_title "AB-123" "" "" "$(echo -e "a\nb\nc")" assert_output "$(cat <<- EOF @@ -2213,6 +2254,39 @@ End" )" } +@test "Highlights current MR link in edited menu" { + + test_menu_content='## Menu + +### Main feature + + * Project A: [MR 11 title](https://gitlab.example.net/proj-A/-/merge_requests/11) + * Project Bee: [MR 21 title](https://gitlab.example.net/proj-B/-/merge_requests/21) (/!\ WIP) + +### Documentation + + * Project Doc: [MR 31 title](https://gitlab.example.net/proj-C/-/merge_requests/31) + +--------------------------------------------------------------------------------' + + run mr_menu_highlight_current "$test_menu_content" "https://gitlab.example.net/proj-B/-/merge_requests/21" + assert_output "$(cat <<- EOF + ## Menu + + ### Main feature + + * Project A: [MR 11 title](https://gitlab.example.net/proj-A/-/merge_requests/11) + * **Project Bee: [MR 21 title](https://gitlab.example.net/proj-B/-/merge_requests/21) (/!\ WIP)** + + ### Documentation + + * Project Doc: [MR 31 title](https://gitlab.example.net/proj-C/-/merge_requests/31) + + -------------------------------------------------------------------------------- + EOF + )" +} + @test "Replaces menu in MR descriptions" { local menu_content="## Menu @@ -2333,6 +2407,129 @@ paragraph. } +@test "Cleans up edited menu" { + run mr_menu_edit_read_file ../../test-menu-contents.md + assert_output "$(cat <<-EOF + ## Menu + + Content line: first + + Content line: before comments + Content line: after comments + + * Menu item 1 + * Menu item 2 + * [Menu item 3](https://example.net) + + Content line ddd + + Content line eee + + -------------------------------------------------------------------------------- + EOF + )" + + run mr_menu_edit_read_file ../../test-empty-menu-contents.md + assert_output "" +} + +@test "Allows menu edit before update" { + load "test_helper/gitlab-mock-menu.bash" + + VISUAL="../../fake-menu-edit.sh" + run mr_menu edit "AB-123" <<< 'y +y +n' + + assert_output --partial "$(cat <<-EOF + ================================================================================ + AB-123 (merge request 1/3) + ================================================================================ + + -------------------------------------------------------------------------------- + Project C: MR 31 title + -------------------------------------------------------------------------------- + + # Merge request with only title + + ## Menu + + * Fake edited menu + * For test + + -------------------------------------------------------------------------------- + + -------------------------------------------------------------------------------- + Updating merge request...OK + EOF + )" + + assert_output --partial "$(cat <<-EOF + ================================================================================ + AB-123 (merge request 2/3) + ================================================================================ + + -------------------------------------------------------------------------------- + Project A: MR 11 title + -------------------------------------------------------------------------------- + + # Lorem ipsum + + ## Menu + + * Fake edited menu + * For test + + -------------------------------------------------------------------------------- + + Merge request with description + and previous menu to be updated. + + -------------------------------------------------------------------------------- + Updating merge request...OK + EOF + )" + + assert_output --partial "$(cat <<-EOF + ================================================================================ + AB-123 (merge request 3/3) + ================================================================================ + + -------------------------------------------------------------------------------- + Project B: MR 21 title + -------------------------------------------------------------------------------- + + # Deserunt laborum nibh + + ## Menu + + * Fake edited menu + * For test + + -------------------------------------------------------------------------------- + + Merge request with description, + but missing menu. + + -------------------------------------------------------------------------------- + EOF + )" + + assert_output --partial "2 merge requests updated" + + refute [ -e '.git/MR_MENU_EDITMSG.md' ] +} + +@test "Aborts menu update when edited menu is empty" { + load "test_helper/gitlab-mock-menu.bash" + + VISUAL="../../fake-menu-edit-empty.sh" + GIT_MR_YES=1 + + run mr_menu edit "AB-123" + assert_output "Empty menu, aborting." +} + ################################################################################ # Status change functions diff --git a/test/test-empty-menu-contents.md b/test/test-empty-menu-contents.md new file mode 100644 index 0000000..973cfa7 --- /dev/null +++ b/test/test-empty-menu-contents.md @@ -0,0 +1,19 @@ + + + + + + + +Beware, lines containing a are completely deleted. + + + + + + + diff --git a/test/test-menu-contents.md b/test/test-menu-contents.md new file mode 100644 index 0000000..e5402aa --- /dev/null +++ b/test/test-menu-contents.md @@ -0,0 +1,30 @@ + + + +Content line: first + + +Content line: before comments + + +Content line: after comments + +Beware, lines containing a are completely deleted. + +* Menu item 1 +* Menu item 2 + * [Menu item 3](https://example.net) + + Content line ddd + + + + +Content line eee + + + diff --git a/test/test_helper/gitlab-mock-menu.bash b/test/test_helper/gitlab-mock-menu.bash index e16b966..7377164 100644 --- a/test/test_helper/gitlab-mock-menu.bash +++ b/test/test_helper/gitlab-mock-menu.bash @@ -1,67 +1,97 @@ gitlab_request() { local f="gitlab_request " - case "$1" in - "merge_requests?scope=all&state=all&view=simple&search=AB-123"*) - # echo "$f✔️ $1" >> gitlab-mock-menu.log - echo '[ - {"iid": 31,"title":"MR 31 title","web_url":"https://'${GITLAB_DOMAIN}'/proj-C/-/merge_requests/31","state":"opened","project_id":3}, - {"iid": 11,"title":"MR 11 title","web_url":"https://'${GITLAB_DOMAIN}'/proj-A/-/merge_requests/11","state":"opened","project_id":1}, - {"iid": 21,"title":"MR 21 title","web_url":"https://'${GITLAB_DOMAIN}'/proj-B/-/merge_requests/21","state":"opened","project_id":2}, - {"iid": 41,"title":"MR 41 title","web_url":"https://'${GITLAB_DOMAIN}'/proj-D/-/merge_requests/41","state":"closed","project_id":4} - ]' - ;; - "projects/proj-A/merge_requests/11/discussions"*) - # echo "$f✔️ $1" >> gitlab-mock-menu.log; - echo '[]'; ;; - "projects/proj-B/merge_requests/21/discussions"*) - # echo "$f✔️ $1" >> gitlab-mock-menu.log; - echo '[]'; ;; - "projects/proj-C/merge_requests/31/discussions"*) - # echo "$f✔️ $1" >> gitlab-mock-menu.log; - echo '[]'; ;; - "projects/proj-D/merge_requests/41/discussions"*) - # echo "$f✔️ $1" >> gitlab-mock-menu.log; - echo '[]'; ;; + local url="$1" + local method="${2:-GET}" - "projects?"*) - # echo "$f✔️ $1" >> gitlab-mock-menu.log - echo '[ - {"id":1,"name":"Project A"}, - {"id":2,"name":"Project B"}, - {"id":3,"name":"Project C"}, - {"id":4,"name":"Project D"} - ]' - ;; + case "$method" in + "GET") case "$url" in + "merge_requests?scope=all&state=all&view=simple&search=AB-123"*) + # echo "$f✔️ $method $url" >> gitlab-mock-menu.log + echo '[ + {"iid": 31,"title":"MR 31 title","web_url":"https://'${GITLAB_DOMAIN}'/proj-C/-/merge_requests/31","state":"opened","project_id":3}, + {"iid": 11,"title":"MR 11 title","web_url":"https://'${GITLAB_DOMAIN}'/proj-A/-/merge_requests/11","state":"opened","project_id":1}, + {"iid": 21,"title":"MR 21 title","web_url":"https://'${GITLAB_DOMAIN}'/proj-B/-/merge_requests/21","state":"opened","project_id":2}, + {"iid": 41,"title":"MR 41 title","web_url":"https://'${GITLAB_DOMAIN}'/proj-D/-/merge_requests/41","state":"closed","project_id":4} + ]' ;; - *) - echo "$f❌ $1" >> gitlab-mock-menu.log - return 1 - ;; + "projects/proj-A/merge_requests/11/discussions"*) + # echo "$f✔️ $method $url" >> gitlab-mock-menu.log; + echo '[]'; ;; + "projects/proj-B/merge_requests/21/discussions"*) + # echo "$f✔️ $method $url" >> gitlab-mock-menu.log; + echo '[]'; ;; + "projects/proj-C/merge_requests/31/discussions"*) + # echo "$f✔️ $method $url" >> gitlab-mock-menu.log; + echo '[]'; ;; + "projects/proj-D/merge_requests/41/discussions"*) + # echo "$f✔️ $method $url" >> gitlab-mock-menu.log; + echo '[]'; ;; + + "projects?"*) + # echo "$f✔️ $method $url" >> gitlab-mock-menu.log + echo '[ + {"id":1,"name":"Project A"}, + {"id":2,"name":"Project B"}, + {"id":3,"name":"Project C"}, + {"id":4,"name":"Project D"} + ]' ;; + *) + echo "$f❌ $method $url" >> gitlab-mock-menu.log + return 1 ;; + esac ;; + + "PUT") case "$url" in + "projects/proj-A/merge_requests/11"*) + # echo "$f✔️ $method $url" >> gitlab-mock-menu.log; + echo '{"fake": "ok"}'; ;; + "projects/proj-B/merge_requests/21"*) + # echo "$f✔️ $method $url" >> gitlab-mock-menu.log; + echo '{"fake": "ok"}'; ;; + "projects/proj-C/merge_requests/31"*) + # echo "$f✔️ $method $url" >> gitlab-mock-menu.log; + echo '{"fake": "ok"}'; ;; + *) + echo "$f❌ $method $url" >> gitlab-mock-menu.log + return 1 ;; + esac ;; esac } gitlab_merge_request() { + local descr11="# Lorem ipsum\n\n" + descr11="${descr11}## Menu\n\n" + descr11="${descr11}* Blabla\n\n" + descr11="${descr11}--------------------------------------------------------------------------------\n\n" + descr11="${descr11}Merge request with description\n" + descr11="${descr11}and previous menu to be updated.\n" + + local descr21="# Deserunt laborum nibh\n\n" + descr21="${descr21}Merge request with description,\n" + descr21="${descr21}but missing menu.\n" + + local descr31="# Merge request with only title" + local f="gitlab_merge_request " case $1 in 11) # echo "$f✔️ $1 $2" >> gitlab-mock-menu.log - echo '{"iid": 11, "title": "MR 11 title", "project_id": 1, + echo '{"iid": 11, "title": "MR 11 title", "project_id": 1, "description": "'${descr11}'", "source_branch":"feature/branch-11", "web_url": "https://'${GITLAB_DOMAIN}'/proj-A/-/merge_requests/11", "head_pipeline": {"status": "running", "web_url": "https://'${GITLAB_DOMAIN}'/proj-A/-/pipelines/11"}, "state": "opened", "labels": ["QA"], "upvotes": 2, "downvotes": 0, "target_branch": "main", "merge_status": "can_be_merged"}';; 21) # echo "$f✔️ $1 $2" >> gitlab-mock-menu.log - echo '{"iid": 21, "title": "MR 21 title", "project_id": 2, + echo '{"iid": 21, "title": "MR 21 title", "project_id": 2, "description": "'${descr21}'", "source_branch":"feature/branch-21", "web_url": "https://'${GITLAB_DOMAIN}'/proj-B/-/merge_requests/21", "head_pipeline": {"status": "failed", "web_url": "https://'${GITLAB_DOMAIN}'/proj-B/-/pipelines/21"}, "state": "opened", "labels": ["Review"], "upvotes": 0, "downvotes": 1, "target_branch": "main"}';; 31) # echo "$f✔️ $1 $2" >> gitlab-mock-menu.log - echo '{"iid": 31, "title": "MR 31 title", "project_id": 3, + echo '{"iid": 31, "title": "MR 31 title", "project_id": 3, "description": "'${descr31}'", "source_branch":"feature/branch-31", "web_url": "https://'${GITLAB_DOMAIN}'/proj-C/-/merge_requests/31", "head_pipeline": {"status": "scheduled", "web_url": "https://'${GITLAB_DOMAIN}'/proj-C/-/pipelines/31"}, @@ -120,3 +150,7 @@ gitlab_merge_request_threads() { return 1; ;; esac } + +clear_screen() { + return 0 # noop +}