├── .gitignore ├── .idea └── vcs.xml ├── .sdkmanrc ├── LICENSE ├── README.markdown ├── build.gradle.kts ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenshot.png ├── settings.gradle.kts └── src └── main ├── java └── com │ └── github │ └── novotnyr │ └── idea │ ├── git │ └── GitService.java │ └── gitlab │ ├── AbstractGitLabCommand.java │ ├── AccessDeniedException.java │ ├── BadMergeRequestException.java │ ├── CommandExecutor.java │ ├── DuplicateMergeRequestException.java │ ├── GitLab.java │ ├── GitLabHttpResponseBody.java │ ├── GitLabHttpResponseException.java │ ├── GitLabIOException.java │ ├── GitLabProject.java │ ├── GitLabProjectNotFoundException.java │ ├── HttpUtils.java │ ├── JsonHttpResponseCallback.java │ ├── MergeRequestRequest.java │ ├── MergeRequestResponse.java │ ├── ProgressIndicator.java │ ├── ProjectId.java │ ├── SearchUsersGitLabCommand.java │ ├── UnsupportedContentTypeException.java │ ├── User.java │ ├── VersionResponse.java │ ├── http │ ├── HttpClientException.java │ ├── HttpClientFactory.java │ └── InsecureTrustManager.java │ └── quickmr │ ├── AlwaysConfirmCreateMergeRequestAction.java │ ├── ConfirmMergeRequestDialog.form │ ├── ConfirmMergeRequestDialog.java │ ├── CreateMergeRequestAction.java │ ├── CreateMergeRequestAndAssignToActionGroup.java │ ├── IllegalGitLabUrlException.java │ ├── JBProgressIndicator.java │ ├── MergeRequestService.java │ ├── NewMergeRequest.java │ ├── PlaceholderResolver.java │ ├── SelectedModule.java │ ├── SettingsNotInitializedException.java │ ├── SourceAndTargetBranchCannotBeEqualException.java │ ├── UserToStringConverter.java │ └── settings │ ├── SelectAssigneeDialog.form │ ├── SelectAssigneeDialog.java │ ├── SettingUtils.java │ ├── Settings.java │ ├── SettingsUi.form │ └── SettingsUi.java └── resources └── META-INF └── plugin.xml /.gitignore: -------------------------------------------------------------------------------- 1 | out/ 2 | .idea/ 3 | *.iml 4 | *.zip 5 | 6 | test/ 7 | gradle.properties 8 | .gradle 9 | build/ 10 | 11 | .intellijPlatform -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.sdkmanrc: -------------------------------------------------------------------------------- 1 | # Enable auto-env through the sdkman_auto_env config 2 | # Add key=value pairs of SDKs to use below 3 | java=11.0.17-tem 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | About this plugin 2 | ================= 3 | 4 | This is an IntelliJ IDEA plug-in that will help you to quickly 5 | create Merge Requests for GitLab projects. 6 | 7 | * Quickly create merge requests with default settings and submit them with a single click 8 | * Specify your favourite merge request assignees 9 | * Supports GitLab API v4 10 | 11 | Using the plug-in 12 | ----------------- 13 | 14 | ### Configure Project Settings 15 | 16 | First, configure the project settings in 17 | **Preferences | Version Control | GitLab Quick Merge Request**. 18 | 19 | ### GitLab URL and GitLab REST Access Token 20 | 21 | Then, specify GitLab URL and REST Access Token and enter 22 | default target branch for Merge Request and a title. 23 | 24 | Usually, the following guidelines apply: 25 | 26 | #### GitLab URLs 27 | * GitLab.com: 28 | * GitLab URL: https://gitlab.com/api/v4 29 | * Personal Access Token: https://gitlab.com/profile/personal_access_tokens 30 | * Private instance hosted at gitlab.example.com: 31 | * GitLab URL: https://gitlab.example.com/api/v4 32 | * Personal Access Token: https://gitlab.example.com/profile/personal_access_tokens 33 | 34 | ### Set Up Assignees 35 | 36 | Then, feel free to add as many assignees as necessary. The first 37 | assignee is a default one that can be used to super-quick 38 | Merge Request. 39 | 40 | 41 | Submitting Merge Requests 42 | ------------------------- 43 | Right-Click on the project, then use the *Git* submenu. 44 | 45 | * *Quick Merge Request* will create a new Merge Request 46 | from the current module with the default settings. It will be assigned 47 | to the favourite assignee 48 | * *Quick Merge Assigned To* will submit a new Merge Request, 49 | but you may choose a default assignee. 50 | 51 | 52 | Compatibility 53 | ------------- 54 | 55 | This plugin is compatible with all JetBrains product that enable 56 | Git VC integration. 57 | 58 | Screenshot 59 | ---------- 60 | ![Screenshot of submenu](./screenshot.png) 61 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType 2 | import org.jetbrains.intellij.platform.gradle.models.ProductRelease 3 | 4 | plugins { 5 | id("java") 6 | id("org.jetbrains.intellij.platform") version "2.0.0-SNAPSHOT" 7 | } 8 | 9 | group = "com.github.novotnyr" 10 | version = "25-SNAPSHOT" 11 | 12 | repositories { 13 | mavenCentral() 14 | intellijPlatform { 15 | defaultRepositories() 16 | } 17 | } 18 | 19 | dependencies { 20 | implementation("com.fasterxml.jackson.core:jackson-databind:2.8.4") 21 | implementation( "com.squareup.okhttp3:okhttp:3.14.9") 22 | 23 | testImplementation("junit:junit:4.13.2") 24 | testImplementation("org.mockito:mockito-core:2.23.4") 25 | 26 | intellijPlatform { 27 | intellijIdeaCommunity("2022.3.3") 28 | bundledPlugin("Git4Idea") 29 | instrumentationTools() 30 | pluginVerifier() 31 | } 32 | } 33 | 34 | intellijPlatform { 35 | pluginConfiguration { 36 | ideaVersion { 37 | sinceBuild = "223" 38 | untilBuild = "241.*" 39 | } 40 | changeNotes = """ 41 | 44 | """.trimIndent() 45 | } 46 | publishing { 47 | val intellijPublishToken: String by project 48 | token = intellijPublishToken 49 | } 50 | verifyPlugin { 51 | ides { 52 | select { 53 | types = listOf(IntelliJPlatformType.IntellijIdeaCommunity) 54 | channels = listOf(ProductRelease.Channel.RELEASE) 55 | sinceBuild = "223" 56 | untilBuild = "241.*" 57 | } 58 | } 59 | } 60 | } 61 | 62 | java { 63 | toolchain { 64 | languageVersion = JavaLanguageVersion.of(17) 65 | } 66 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/novotnyr/gitlab-quickmr-idea-plugin/772296c71a27834ffe6ab96e0490425e965b8bec/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/novotnyr/gitlab-quickmr-idea-plugin/772296c71a27834ffe6ab96e0490425e965b8bec/screenshot.png -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "gitlab-quickmr-plugin" 2 | pluginManagement { 3 | repositories { 4 | maven("https://oss.sonatype.org/content/repositories/snapshots/") 5 | gradlePluginPortal() 6 | } 7 | } -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/git/GitService.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.git; 2 | 3 | import com.github.novotnyr.idea.gitlab.quickmr.SelectedModule; 4 | import com.intellij.openapi.diagnostic.Logger; 5 | import com.intellij.openapi.project.Project; 6 | import com.intellij.openapi.vcs.VcsException; 7 | import com.intellij.openapi.vcs.history.VcsRevisionDescription; 8 | import com.intellij.openapi.vfs.VirtualFile; 9 | import com.intellij.vcsUtil.VcsUtil; 10 | import git4idea.GitLocalBranch; 11 | import git4idea.GitUtil; 12 | import git4idea.branch.GitBranchesCollection; 13 | import git4idea.history.GitHistoryUtils; 14 | import git4idea.repo.GitRemote; 15 | import git4idea.repo.GitRepository; 16 | import git4idea.repo.GitRepositoryManager; 17 | 18 | import java.util.Collection; 19 | import java.util.Optional; 20 | import java.util.regex.Matcher; 21 | import java.util.regex.Pattern; 22 | 23 | public class GitService { 24 | private static final Logger LOG = Logger.getInstance("#com.github.novotnyr.idea.git.GitService"); 25 | 26 | public Collection getLocalBranches(Project project, VirtualFile file) { 27 | GitRepositoryManager repositoryManager = GitUtil.getRepositoryManager(project); 28 | GitRepository repo = repositoryManager.getRepositoryForFile(file); 29 | if (repo == null) { 30 | return null; 31 | } 32 | GitBranchesCollection branches = repo.getBranches(); 33 | return branches.getLocalBranches(); 34 | } 35 | 36 | public String getCurrentBranch(SelectedModule module) { 37 | return getCurrentBranch(module.getProject(), module.getFile()); 38 | } 39 | 40 | public String getCurrentBranch(Project project, VirtualFile file) { 41 | GitRepositoryManager repositoryManager = GitUtil.getRepositoryManager(project); 42 | GitRepository repo = repositoryManager.getRepositoryForFile(file); 43 | if (repo == null) { 44 | return null; 45 | } 46 | GitLocalBranch currentBranch = repo.getCurrentBranch(); 47 | if (currentBranch == null) { 48 | return null; 49 | } 50 | return currentBranch.getName(); 51 | } 52 | 53 | public String getProjectGitUrl(SelectedModule selectedModule) { 54 | GitRepositoryManager repositoryManager = GitUtil.getRepositoryManager(selectedModule.getProject()); 55 | GitRepository repo = repositoryManager.getRepositoryForFile(selectedModule.getFile()); 56 | if (repo == null) { 57 | return null; 58 | } 59 | for (GitRemote remote : repo.getRemotes()) { 60 | return remote.getFirstUrl(); 61 | } 62 | return null; 63 | } 64 | 65 | public static final Pattern pattern = Pattern.compile("(?:git|ssh|https?|git@[-\\w.]+):(//)?(.*?)(\\.git)(/?|#[-\\d\\w._]+?)$"); 66 | 67 | public String getRepoPathWithoutDotGit(String url) { 68 | Matcher matcher = pattern.matcher(url); 69 | if (matcher.matches()) { 70 | String repoId = matcher.group(2); 71 | if (url.startsWith("http")) { 72 | // Let's extract away hostname. 73 | // E. g. gitlab.com/example/dummy-project is transformed to 74 | // example/dummy-project 75 | repoId = repoId.substring(repoId.indexOf("/") + 1); 76 | } 77 | return repoId; 78 | } 79 | return null; 80 | } 81 | 82 | public Optional getLastCommitMessage(Project project) { 83 | try { 84 | return Optional.ofNullable(GitHistoryUtils.getCurrentRevisionDescription(project, VcsUtil 85 | .getFilePath(project.getBaseDir()))) 86 | .map(VcsRevisionDescription::getCommitMessage); 87 | } catch (VcsException e) { 88 | LOG.error("Unable to load last commit message", e); 89 | return Optional.empty(); 90 | } 91 | } 92 | 93 | public Optional getLastCommitMessageSubject(Project project) { 94 | return getLastCommitMessage(project) 95 | .filter(commitMessage -> commitMessage.contains(System.lineSeparator())) 96 | .map(commitMessage -> commitMessage.substring(0, commitMessage.indexOf(System.lineSeparator())).trim()); 97 | } 98 | 99 | public Optional getLastCommitMessageBody(Project project) { 100 | return getLastCommitMessage(project) 101 | .filter(commitMessage -> commitMessage.contains(System.lineSeparator())) 102 | .map(commitMessage -> commitMessage.substring(commitMessage.indexOf(System.lineSeparator())).trim()); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/AbstractGitLabCommand.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab; 2 | 3 | import com.google.gson.Gson; 4 | import okhttp3.OkHttpClient; 5 | import okhttp3.Request; 6 | 7 | import java.util.concurrent.Callable; 8 | import java.util.concurrent.CompletableFuture; 9 | 10 | import static com.github.novotnyr.idea.gitlab.GitLab.PRIVATE_TOKEN_HEADER; 11 | 12 | public abstract class AbstractGitLabCommand implements Callable> { 13 | protected final String baseUri; 14 | 15 | protected final String privateToken; 16 | 17 | protected final OkHttpClient httpClient; 18 | 19 | protected final Gson gson; 20 | 21 | public AbstractGitLabCommand(String baseUri, String privateToken, OkHttpClient httpClient, Gson gson) { 22 | this.baseUri = baseUri; 23 | this.privateToken = privateToken; 24 | this.httpClient = httpClient; 25 | this.gson = gson; 26 | } 27 | 28 | protected Request.Builder prepareRequest(String urlSuffix) { 29 | return new Request.Builder() 30 | .url(this.baseUri + urlSuffix) 31 | .addHeader(PRIVATE_TOKEN_HEADER, this.privateToken); 32 | } 33 | 34 | @Override 35 | public abstract CompletableFuture call(); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/AccessDeniedException.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab; 2 | 3 | public class AccessDeniedException extends RuntimeException { 4 | // empty 5 | } -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/BadMergeRequestException.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab; 2 | 3 | public class BadMergeRequestException extends Throwable { 4 | public BadMergeRequestException(String message) { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/CommandExecutor.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab; 2 | 3 | import java.util.concurrent.CompletableFuture; 4 | 5 | @FunctionalInterface 6 | public interface CommandExecutor { 7 | CompletableFuture execute(AbstractGitLabCommand command); 8 | 9 | CommandExecutor DEFAULT = new CommandExecutor() { 10 | @Override 11 | public CompletableFuture execute(AbstractGitLabCommand command) { 12 | return command.call(); 13 | } 14 | }; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/DuplicateMergeRequestException.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab; 2 | 3 | public class DuplicateMergeRequestException extends RuntimeException { 4 | 5 | public DuplicateMergeRequestException() { 6 | super(); 7 | } 8 | 9 | public DuplicateMergeRequestException(String msg) { 10 | super(msg); 11 | } 12 | 13 | public DuplicateMergeRequestException(String message, Throwable cause) { 14 | super(message, cause); 15 | } 16 | 17 | public DuplicateMergeRequestException(Throwable cause) { 18 | super(cause); 19 | } 20 | } -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/GitLab.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab; 2 | 3 | import com.github.novotnyr.idea.gitlab.http.HttpClientFactory; 4 | import com.google.gson.Gson; 5 | import okhttp3.Call; 6 | import okhttp3.HttpUrl; 7 | import okhttp3.MediaType; 8 | import okhttp3.OkHttpClient; 9 | import okhttp3.Request; 10 | import okhttp3.RequestBody; 11 | import okhttp3.Response; 12 | import okhttp3.ResponseBody; 13 | import org.apache.commons.lang.StringUtils; 14 | import org.apache.http.client.HttpResponseException; 15 | import org.jetbrains.annotations.NotNull; 16 | import org.jetbrains.annotations.Nullable; 17 | 18 | import java.io.IOException; 19 | import java.util.List; 20 | import java.util.Optional; 21 | import java.util.concurrent.CompletableFuture; 22 | 23 | public class GitLab { 24 | public static final String PRIVATE_TOKEN_HEADER = "Private-Token"; 25 | 26 | private String baseUri; 27 | 28 | private String privateToken; 29 | 30 | private OkHttpClient httpClient; 31 | 32 | private Gson gson = new Gson(); 33 | 34 | public GitLab(String baseUri, String privateToken) { 35 | this(baseUri, privateToken, false); 36 | } 37 | 38 | public GitLab(String baseUri, String privateToken, boolean allowSelfSignedTls) { 39 | this.baseUri = baseUri; 40 | this.privateToken = privateToken; 41 | 42 | HttpClientFactory httpClientFactory = HttpClientFactory.getInstance(); 43 | this.httpClient = allowSelfSignedTls ? httpClientFactory.getInsecureHttpClient() : httpClientFactory.getHttpClient(); 44 | } 45 | 46 | public CompletableFuture version() { 47 | String url = this.baseUri + "/version"; 48 | 49 | CompletableFuture result = new CompletableFuture<>(); 50 | if (HttpUrl.parse(url) == null) { 51 | result.completeExceptionally(new HttpResponseException(500, "Incorrect GitLab URL")); 52 | return result; 53 | } 54 | if (this.baseUri.endsWith("/")) { 55 | result.completeExceptionally(new HttpResponseException(500, "Remove last slash from URL")); 56 | return result; 57 | } 58 | 59 | Request request = prepareRequest("/version").build(); 60 | this.httpClient.newCall(request) 61 | .enqueue(new JsonHttpResponseCallback<>(VersionResponse.class, result, this.gson) { 62 | @Override 63 | protected void onRawResponseBody(Response response, String rawResponseBodyString) { 64 | if (response.code() != 200) { 65 | String contentType = getContentType(response); 66 | result.completeExceptionally(new GitLabHttpResponseException(response.code(), response.message(), rawResponseBodyString, contentType)); 67 | } else { 68 | super.onRawResponseBody(response, rawResponseBodyString); 69 | } 70 | } 71 | 72 | }); 73 | return result; 74 | } 75 | 76 | public CompletableFuture> searchProject(String projectName) { 77 | String url = this.baseUri + "/projects?search=" + projectName; 78 | 79 | Request request = new Request.Builder() 80 | .url(url) 81 | .addHeader(PRIVATE_TOKEN_HEADER, this.privateToken) 82 | .get() 83 | .build(); 84 | 85 | CompletableFuture> result = new CompletableFuture<>(); 86 | 87 | Call call = httpClient.newCall(request); 88 | call.enqueue(JsonHttpResponseCallback.ofList(result, gson)); 89 | return result; 90 | } 91 | 92 | public CompletableFuture> searchUsers2(String username, int batchSize, CommandExecutor commandExecutor, ProgressIndicator progressIndicator) { 93 | SearchUsersGitLabCommand command = new SearchUsersGitLabCommand(this.baseUri, this.privateToken, this.httpClient, this.gson, progressIndicator, username); 94 | return commandExecutor.execute(command); 95 | } 96 | 97 | public CompletableFuture> searchUsers(String username) { 98 | Request request = prepareRequest("/users?username=" + username + "&per_page=300&active=true") 99 | .build(); 100 | 101 | CompletableFuture> result = new CompletableFuture<>(); 102 | Call call = httpClient.newCall(request); 103 | call.enqueue(JsonHttpResponseCallback.ofList(result, gson)); 104 | return result; 105 | } 106 | 107 | public CompletableFuture> listUsers() { 108 | Request request = prepareRequest("/users?per_page=300") 109 | .build(); 110 | 111 | CompletableFuture> result = new CompletableFuture<>(); 112 | 113 | Call call = httpClient.newCall(request); 114 | call.enqueue(JsonHttpResponseCallback.ofList(result, gson)); 115 | return result; 116 | } 117 | 118 | public CompletableFuture findUserByName(String username) { 119 | Request request = prepareRequest("/users?username=" + username) 120 | .build(); 121 | 122 | CompletableFuture> result = new CompletableFuture<>(); 123 | 124 | httpClient 125 | .newCall(request) 126 | .enqueue(JsonHttpResponseCallback.ofList(result, this.gson)); 127 | return result.thenApply(users -> users.get(0)); 128 | } 129 | 130 | public CompletableFuture createMergeRequest(String gitLabProjectId, MergeRequestRequest mergeRequestRequest) { 131 | return doCreateMergeRequest(ProjectId.of(gitLabProjectId), mergeRequestRequest); 132 | } 133 | 134 | public CompletableFuture createMergeRequest(long projectId, MergeRequestRequest mergeRequestRequest) { 135 | return doCreateMergeRequest(ProjectId.of(projectId), mergeRequestRequest); 136 | } 137 | 138 | protected CompletableFuture doCreateMergeRequest(ProjectId projectId, MergeRequestRequest mergeRequestRequest) { 139 | String url = this.baseUri + "/projects/" + projectId.getUrlEncoded() + "/merge_requests"; 140 | 141 | Request request = new Request.Builder() 142 | .url(url) 143 | .addHeader(PRIVATE_TOKEN_HEADER, this.privateToken) 144 | .post(RequestBody.create(MediaType.parse("application/json"), this.gson.toJson(mergeRequestRequest))) 145 | .build(); 146 | 147 | CompletableFuture result = new CompletableFuture<>(); 148 | 149 | Call call = httpClient.newCall(request); 150 | call.enqueue(new JsonHttpResponseCallback<>(MergeRequestResponse.class, result, this.gson) { 151 | @Override 152 | public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { 153 | if (response.code() == 409) { 154 | completeExceptionally(result, new DuplicateMergeRequestException(), response); 155 | return; 156 | } 157 | if (response.code() == 400) { 158 | completeExceptionally(result, new BadMergeRequestException(response.message()), response); 159 | return; 160 | } 161 | if (response.code() == 403 || response.code() == 401) { 162 | completeExceptionally(result, new AccessDeniedException(), response); 163 | return; 164 | } 165 | 166 | if (!isJson(response)) { 167 | completeExceptionally(result, new UnsupportedContentTypeException("GitLab API is misconfigured. Only JSON replies are supported"), response); 168 | return; 169 | } 170 | try (ResponseBody body = response.body()) { 171 | if (body == null) { 172 | result.completeExceptionally(new GitLabHttpResponseException(response.code(), response.message(), null, null)); 173 | return; 174 | } 175 | String json = body.string(); 176 | logRawResponseBody(response, json); 177 | if (isGitLabProjectNotFound(response, json)) { 178 | result.completeExceptionally(GitLabProjectNotFoundException.of(projectId)); 179 | return; 180 | } 181 | MergeRequestResponse mergeRequestResponse = gson.fromJson(json, MergeRequestResponse.class); 182 | result.complete(mergeRequestResponse); 183 | } 184 | } 185 | }); 186 | 187 | return result; 188 | } 189 | 190 | @Nullable 191 | private String getContentType(@Nullable ResponseBody body) { 192 | if (body == null) { 193 | return null; 194 | } 195 | MediaType mediaType = body.contentType(); 196 | if (mediaType == null) { 197 | return null; 198 | } 199 | return mediaType.toString(); 200 | } 201 | 202 | private boolean isGitLabProjectNotFound(Response response, String json) { 203 | // {"message":"404 Project Not Found"} 204 | return 404 == response.code() && json.contains("Project Not Found"); 205 | } 206 | 207 | private boolean isJson(Response response) { 208 | return Optional.ofNullable(response.header("Content-Type")) 209 | .map(MediaType::parse) 210 | .filter(contentType -> "application".equals(contentType.type()) && "json".equals(contentType.subtype())) 211 | .isPresent(); 212 | } 213 | 214 | protected Request.Builder prepareRequest(String urlSuffix) { 215 | return new Request.Builder() 216 | .url(this.baseUri + urlSuffix) 217 | .addHeader(PRIVATE_TOKEN_HEADER, this.privateToken); 218 | } 219 | 220 | public static String getBaseUrl(String gitLabRestApiUrl) { 221 | String url = gitLabRestApiUrl; 222 | url = StringUtils.removeEnd(url, "/"); 223 | url = StringUtils.removeEnd(url, "/api/v4"); 224 | return url; 225 | } 226 | 227 | protected String getContentType(Response response) { 228 | List headers = response.headers("Content-Type"); 229 | if (headers.isEmpty()) { 230 | return "application/octet-stream"; 231 | } 232 | return headers.get(0); 233 | } 234 | 235 | public static String getAccessTokenWebPageUrl(String gitLabBaseUrl) { 236 | return gitLabBaseUrl + "/profile/personal_access_tokens"; 237 | } 238 | } 239 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/GitLabHttpResponseBody.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab; 2 | 3 | import org.apache.commons.lang.StringEscapeUtils; 4 | import org.jetbrains.annotations.NotNull; 5 | import org.jetbrains.annotations.Nullable; 6 | 7 | public class GitLabHttpResponseBody { 8 | public enum Type { 9 | HTML, UNKNOWN 10 | } 11 | 12 | @NotNull 13 | private String body; 14 | 15 | private boolean isUnavailable; 16 | 17 | private Type type; 18 | 19 | public GitLabHttpResponseBody(@Nullable String responseBody, String contentType) { 20 | this(responseBody, isHtmlContentType(contentType) ? Type.HTML : Type.UNKNOWN); 21 | } 22 | 23 | 24 | public GitLabHttpResponseBody(@Nullable String responseBody, Type type) { 25 | this.type = type; 26 | if (responseBody == null) { 27 | this.isUnavailable = true; 28 | this.body = ""; 29 | } else { 30 | this.body = responseBody; 31 | } 32 | } 33 | 34 | public String asHtml() { 35 | if (this.isUnavailable) { 36 | return ""; 37 | } 38 | if (this.body.isBlank()) { 39 | return ""; 40 | } 41 | String html = this.body; 42 | if (this.type == Type.HTML) { 43 | html = StringEscapeUtils.escapeHtml(html); 44 | } 45 | if (this.body.length() >= 128) { 46 | html = html.substring(0, 128) + "..."; 47 | } 48 | return "
" + html + "
"; 49 | } 50 | 51 | public boolean containsCaseInsensitive(String value) { 52 | return this.body.toLowerCase().contains(value.toLowerCase()); 53 | } 54 | 55 | public static boolean isHtmlContentType(String contentType) { 56 | return contentType != null && ( 57 | contentType.startsWith("text/html") 58 | || contentType.startsWith("application/xhtml+xml") 59 | ); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/GitLabHttpResponseException.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab; 2 | 3 | import okhttp3.Response; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | public class GitLabHttpResponseException extends RuntimeException { 7 | private final int statusCode; 8 | 9 | private final String responseMessage; 10 | 11 | private final GitLabHttpResponseBody responseBody; 12 | 13 | private final String contentType; 14 | 15 | public GitLabHttpResponseException(int statusCode, String responseMessage, String responseBody, String contentType) { 16 | super(responseMessage); 17 | this.statusCode = statusCode; 18 | this.responseMessage = responseMessage; 19 | this.responseBody = new GitLabHttpResponseBody(responseBody, contentType); 20 | this.contentType = contentType; 21 | } 22 | 23 | public GitLabHttpResponseException(int statusCode, String responseMessage, String responseBody, String contentType, Throwable cause) { 24 | super(responseMessage, cause); 25 | this.statusCode = statusCode; 26 | this.responseMessage = responseMessage; 27 | this.responseBody = new GitLabHttpResponseBody(responseBody, contentType); 28 | this.contentType = contentType; 29 | } 30 | 31 | public static GitLabHttpResponseException ofNullResponse(@NotNull Response response) { 32 | return new GitLabHttpResponseException(response.code(), response.message(), null, null); 33 | } 34 | 35 | public int getStatusCode() { 36 | return statusCode; 37 | } 38 | 39 | public String getResponseMessage() { 40 | return responseMessage; 41 | } 42 | 43 | public GitLabHttpResponseBody getResponseBody() { 44 | return responseBody; 45 | } 46 | 47 | public String getContentType() { 48 | return contentType; 49 | } 50 | 51 | public static boolean isHtmlContentType(String contentType) { 52 | return contentType != null && ( 53 | contentType.startsWith("text/html") 54 | || contentType.startsWith("application/xhtml+xml") 55 | ); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/GitLabIOException.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab; 2 | 3 | public class GitLabIOException extends RuntimeException { 4 | public GitLabIOException(String message, Throwable cause) { 5 | super(message, cause); 6 | } 7 | } -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/GitLabProject.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab; 2 | 3 | public class GitLabProject { 4 | private long id; 5 | 6 | public long getId() { 7 | return id; 8 | } 9 | 10 | public void setId(long id) { 11 | this.id = id; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/GitLabProjectNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab; 2 | 3 | public class GitLabProjectNotFoundException extends RuntimeException { 4 | public GitLabProjectNotFoundException(String message) { 5 | super(message); 6 | } 7 | 8 | public static GitLabProjectNotFoundException of(ProjectId projectId) { 9 | return new GitLabProjectNotFoundException("GitLab project '" + projectId + "' not found. Do GitLab URL and Git remote match?"); 10 | } 11 | } -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/HttpUtils.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab; 2 | 3 | import okhttp3.Response; 4 | import okhttp3.ResponseBody; 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | public abstract class HttpUtils { 8 | @NotNull 9 | public static ResponseBody assertHasBody(Response response, ResponseBody body) { 10 | if (body == null) { 11 | throw GitLabHttpResponseException.ofNullResponse(response); 12 | } 13 | return body; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/JsonHttpResponseCallback.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.JsonSyntaxException; 5 | import com.google.gson.reflect.TypeToken; 6 | import com.intellij.openapi.diagnostic.Logger; 7 | import okhttp3.Call; 8 | import okhttp3.Callback; 9 | import okhttp3.Response; 10 | import okhttp3.ResponseBody; 11 | import org.jetbrains.annotations.NotNull; 12 | 13 | import java.io.IOException; 14 | import java.lang.reflect.Type; 15 | import java.net.SocketTimeoutException; 16 | import java.util.List; 17 | import java.util.concurrent.CompletableFuture; 18 | 19 | import static com.github.novotnyr.idea.gitlab.HttpUtils.assertHasBody; 20 | 21 | public class JsonHttpResponseCallback implements Callback { 22 | protected final Logger log = Logger.getInstance("#" + JsonHttpResponseCallback.class.getName()); 23 | 24 | private Type typeToken; 25 | 26 | private final CompletableFuture result; 27 | 28 | private final Gson gson; 29 | 30 | private JsonHttpResponseCallback(CompletableFuture result, Gson gson) { 31 | this.result = result; 32 | this.gson = gson; 33 | } 34 | 35 | public JsonHttpResponseCallback(Class resultClass, CompletableFuture result, Gson gson) { 36 | this.typeToken = new TypeToken(){}.getType(); 37 | this.result = result; 38 | this.gson = gson; 39 | } 40 | 41 | public static JsonHttpResponseCallback ofList(CompletableFuture> result, Gson gson) { 42 | JsonHttpResponseCallback callback = new JsonHttpResponseCallback(result, gson); 43 | callback.typeToken = new TypeToken>(){}.getType(); 44 | 45 | return callback; 46 | } 47 | 48 | @Override 49 | public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { 50 | try(ResponseBody body = response.body()) { 51 | String json = assertHasBody(response, body).string(); 52 | onRawResponseBody(response, json); 53 | Type typeToken = new TypeToken(){}.getType(); 54 | T deserializedJson = this.gson.fromJson(json, typeToken); 55 | result.complete(handleResponse(response, body, json, deserializedJson)); 56 | } catch (JsonSyntaxException e) { 57 | result.completeExceptionally(e); 58 | } 59 | } 60 | 61 | @Override 62 | public void onFailure(@NotNull Call call, @NotNull IOException e) { 63 | if (e instanceof SocketTimeoutException) { 64 | result.completeExceptionally(new GitLabIOException("GitLab network connectivity failed: " + e.getMessage(), e)); 65 | return; 66 | } 67 | result.completeExceptionally(e); 68 | } 69 | 70 | protected void onRawResponseBody(Response response, String rawResponseBodyString) { 71 | logRawResponseBody(response, rawResponseBodyString); 72 | } 73 | 74 | protected void logRawResponseBody(Response response, String rawResponseBodyString) { 75 | log.debug("HTTP " + response.code() + "\n" + rawResponseBodyString); 76 | } 77 | 78 | protected void logAndConsumeRawResponseBody(Response response) { 79 | try(ResponseBody body = response.body()) { 80 | String bodyPayload = assertHasBody(response, body).string(); 81 | logRawResponseBody(response, bodyPayload); 82 | } catch (IOException e) { 83 | log.debug("Cannot log and consume response body", e); 84 | } 85 | } 86 | 87 | protected void completeExceptionally(CompletableFuture result, Throwable throwable, Response response) { 88 | logAndConsumeRawResponseBody(response); 89 | result.completeExceptionally(throwable); 90 | } 91 | protected T handleResponse(Response response, ResponseBody body, String json, T object) { 92 | return object; 93 | } 94 | 95 | private boolean assertNotNullBody(Response response) { 96 | ResponseBody body = response.body(); 97 | if (body == null) { 98 | result.completeExceptionally(GitLabHttpResponseException.ofNullResponse(response)); 99 | return false; 100 | } 101 | return true; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/MergeRequestRequest.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | public class MergeRequestRequest { 6 | @SerializedName("source_branch") 7 | private String sourceBranch; 8 | 9 | @SerializedName("target_branch") 10 | private String targetBranch; 11 | 12 | private String title; 13 | 14 | private String description; 15 | 16 | @SerializedName("assignee_id") 17 | private Long assigneeId; 18 | 19 | @SerializedName("remove_source_branch") 20 | private boolean removeSourceBranch; 21 | 22 | private String labels; 23 | 24 | private boolean squash; 25 | 26 | public String getSourceBranch() { 27 | return sourceBranch; 28 | } 29 | 30 | public void setSourceBranch(String sourceBranch) { 31 | this.sourceBranch = sourceBranch; 32 | } 33 | 34 | public String getTargetBranch() { 35 | return targetBranch; 36 | } 37 | 38 | public void setTargetBranch(String targetBranch) { 39 | this.targetBranch = targetBranch; 40 | } 41 | 42 | public String getTitle() { 43 | return title; 44 | } 45 | 46 | public void setTitle(String title) { 47 | this.title = title; 48 | } 49 | 50 | public String getDescription() { 51 | return description; 52 | } 53 | 54 | public void setDescription(String description) { 55 | this.description = description; 56 | } 57 | 58 | public Long getAssigneeId() { 59 | return assigneeId; 60 | } 61 | 62 | public void setAssigneeId(Long assigneeId) { 63 | this.assigneeId = assigneeId; 64 | } 65 | 66 | public boolean isRemoveSourceBranch() { 67 | return removeSourceBranch; 68 | } 69 | 70 | public void setRemoveSourceBranch(boolean removeSourceBranch) { 71 | this.removeSourceBranch = removeSourceBranch; 72 | } 73 | 74 | public String getLabels() { 75 | return labels; 76 | } 77 | 78 | public void setLabels(String labels) { 79 | this.labels = labels; 80 | } 81 | 82 | public boolean isSquash() { 83 | return squash; 84 | } 85 | 86 | public void setSquash(boolean squash) { 87 | this.squash = squash; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/MergeRequestResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | public class MergeRequestResponse { 6 | @SerializedName("iid") 7 | private String number; 8 | 9 | @SerializedName("web_url") 10 | private String webUrl; 11 | 12 | @SerializedName("target_branch") 13 | private String targetBranch; 14 | 15 | @SerializedName("source_branch") 16 | private String sourceBranch; 17 | 18 | private User assignee; 19 | 20 | public String getWebUrl() { 21 | return webUrl; 22 | } 23 | 24 | public void setWebUrl(String webUrl) { 25 | this.webUrl = webUrl; 26 | } 27 | 28 | public String getNumber() { 29 | return number; 30 | } 31 | 32 | public void setNumber(String number) { 33 | this.number = number; 34 | } 35 | 36 | public String getTargetBranch() { 37 | return targetBranch; 38 | } 39 | 40 | public void setTargetBranch(String targetBranch) { 41 | this.targetBranch = targetBranch; 42 | } 43 | 44 | public String getSourceBranch() { 45 | return sourceBranch; 46 | } 47 | 48 | public void setSourceBranch(String sourceBranch) { 49 | this.sourceBranch = sourceBranch; 50 | } 51 | 52 | public User getAssignee() { 53 | return assignee; 54 | } 55 | 56 | public String getAssigneeName() { 57 | if (this.assignee == null) { 58 | return null; 59 | } 60 | return this.assignee.getName(); 61 | } 62 | 63 | public void setAssignee(User assignee) { 64 | this.assignee = assignee; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/ProgressIndicator.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab; 2 | 3 | public interface ProgressIndicator { 4 | void setPercents(float percents); 5 | boolean isCancelled(); 6 | 7 | ProgressIndicator NONE = new ProgressIndicator() { 8 | @Override 9 | public void setPercents(float percents) { 10 | /* do nothing */ 11 | } 12 | 13 | @Override 14 | public boolean isCancelled() { 15 | return false; 16 | } 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/ProjectId.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab; 2 | 3 | import java.net.URLEncoder; 4 | import java.nio.charset.StandardCharsets; 5 | 6 | public class ProjectId { 7 | private final String projectId; 8 | 9 | private ProjectId(String projectId) { 10 | this.projectId = projectId; 11 | } 12 | 13 | protected static ProjectId of(String projectId) { 14 | return new ProjectId(projectId); 15 | } 16 | 17 | public static ProjectId of(long projectId) { 18 | return new ProjectId(Long.toString(projectId)); 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return this.projectId; 24 | } 25 | 26 | public String getUrlEncoded() { 27 | return URLEncoder.encode(this.projectId, StandardCharsets.UTF_8); 28 | } 29 | } -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/SearchUsersGitLabCommand.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab; 2 | 3 | import com.google.gson.Gson; 4 | import okhttp3.Call; 5 | import okhttp3.OkHttpClient; 6 | import okhttp3.Request; 7 | import okhttp3.Response; 8 | import okhttp3.ResponseBody; 9 | import okhttp3.internal.Util; 10 | 11 | import java.io.IOException; 12 | import java.util.ArrayList; 13 | import java.util.Arrays; 14 | import java.util.Collections; 15 | import java.util.List; 16 | import java.util.concurrent.CompletableFuture; 17 | 18 | import static com.github.novotnyr.idea.gitlab.HttpUtils.assertHasBody; 19 | 20 | public class SearchUsersGitLabCommand extends AbstractGitLabCommand> { 21 | 22 | private final ProgressIndicator progressIndicator; 23 | 24 | private final String username; 25 | 26 | public SearchUsersGitLabCommand(String baseUri, String privateToken, OkHttpClient httpClient, Gson gson, ProgressIndicator progressIndicator, String username) { 27 | super(baseUri, privateToken, httpClient, gson); 28 | this.progressIndicator = progressIndicator; 29 | this.username = username; 30 | } 31 | 32 | @Override 33 | public CompletableFuture> call() { 34 | CompletableFuture> result = new CompletableFuture<>(); 35 | this.progressIndicator.setPercents(0); 36 | 37 | List allUsers = new ArrayList<>(); 38 | int page = 1; 39 | while (true) { 40 | if (this.progressIndicator.isCancelled()) { 41 | return emptyResult(); 42 | } 43 | 44 | int perPage = 25; 45 | Request request = prepareRequest(String.format("/users?search=%s&page=%s&per_page=%s&active=true", this.username, page, perPage)) 46 | .build(); 47 | 48 | Call call = httpClient.newCall(request); 49 | ResponseBody body = null; 50 | UserBatch userBatch; 51 | try { 52 | Response response = call.execute(); 53 | if (response.code() != 200) { 54 | result.completeExceptionally(new IOException("Wrong API call")); 55 | return result; 56 | } 57 | body = assertHasBody(response, response.body()); 58 | String json = body.string(); 59 | User[] users = gson.fromJson(json, User[].class); 60 | //noinspection DataFlowIssue 61 | page = Integer.parseInt(response.header("X-Page", "1")); 62 | String xTotalPages = response.header("X-Total-Pages"); 63 | int totalPages = Integer.MAX_VALUE; 64 | if (xTotalPages != null) { 65 | totalPages = Integer.parseInt(xTotalPages); 66 | this.progressIndicator.setPercents(page/(float) totalPages); 67 | } else { 68 | this.progressIndicator.setPercents(-1); 69 | } 70 | userBatch = new UserBatch(users, page, totalPages); 71 | allUsers.add(userBatch); 72 | 73 | } catch (IOException e) { 74 | e.printStackTrace(); 75 | break; 76 | } finally { 77 | Util.closeQuietly(body); 78 | } 79 | if (userBatch.isLastPage()) { 80 | break; 81 | } 82 | page++; 83 | } 84 | 85 | List r = new ArrayList<>(); 86 | for (UserBatch allUser : allUsers) { 87 | r.addAll(allUser.getUsers()); 88 | } 89 | 90 | result.complete(r); 91 | return result; 92 | } 93 | 94 | private CompletableFuture> emptyResult() { 95 | CompletableFuture> result = new CompletableFuture<>(); 96 | result.complete(Collections.emptyList()); 97 | return result; 98 | } 99 | 100 | private static class UserBatch { 101 | private final List users; 102 | 103 | private final int page; 104 | 105 | private final int totalPages; 106 | 107 | public UserBatch(User[] users, int page, int totalPages) { 108 | this.users = Arrays.asList(users); 109 | this.page = page; 110 | this.totalPages = totalPages; 111 | } 112 | 113 | public List getUsers() { 114 | return this.users; 115 | } 116 | 117 | public boolean isLastPage() { 118 | return this.page == this.totalPages; 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/UnsupportedContentTypeException.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab; 2 | 3 | public class UnsupportedContentTypeException extends RuntimeException { 4 | 5 | public UnsupportedContentTypeException() { 6 | super(); 7 | } 8 | 9 | public UnsupportedContentTypeException(String msg) { 10 | super(msg); 11 | } 12 | 13 | public UnsupportedContentTypeException(String message, Throwable cause) { 14 | super(message, cause); 15 | } 16 | 17 | public UnsupportedContentTypeException(Throwable cause) { 18 | super(cause); 19 | } 20 | } -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/User.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab; 2 | 3 | import java.util.Objects; 4 | 5 | public class User { 6 | public static final User NONE = new User(-1); 7 | 8 | private long id; 9 | 10 | private String name; 11 | 12 | private String username; 13 | 14 | public User() { 15 | // empty constructor 16 | } 17 | 18 | public User(long id) { 19 | this.id = id; 20 | } 21 | 22 | public long getId() { 23 | return id; 24 | } 25 | 26 | public void setId(long id) { 27 | this.id = id; 28 | } 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public void setName(String name) { 35 | this.name = name; 36 | } 37 | 38 | public String getUsername() { 39 | return username; 40 | } 41 | 42 | public void setUsername(String username) { 43 | this.username = username; 44 | } 45 | 46 | @Override 47 | public boolean equals(Object o) { 48 | if (this == o) return true; 49 | if (!(o instanceof User)) return false; 50 | User user = (User) o; 51 | return getId() == user.getId() && 52 | Objects.equals(getName(), user.getName()) && 53 | Objects.equals(getUsername(), user.getUsername()); 54 | } 55 | 56 | @Override 57 | public int hashCode() { 58 | return Objects.hash(getId(), getName(), getUsername()); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/VersionResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab; 2 | 3 | public class VersionResponse { 4 | private String version; 5 | 6 | private String revision; 7 | 8 | public String getVersion() { 9 | return version; 10 | } 11 | 12 | public void setVersion(String version) { 13 | this.version = version; 14 | } 15 | 16 | public String getRevision() { 17 | return revision; 18 | } 19 | 20 | public void setRevision(String revision) { 21 | this.revision = revision; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/http/HttpClientException.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab.http; 2 | 3 | public class HttpClientException extends RuntimeException { 4 | 5 | public HttpClientException() { 6 | super(); 7 | } 8 | 9 | public HttpClientException(String msg) { 10 | super(msg); 11 | } 12 | 13 | public HttpClientException(String message, Throwable cause) { 14 | super(message, cause); 15 | } 16 | 17 | public HttpClientException(Throwable cause) { 18 | super(cause); 19 | } 20 | } -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/http/HttpClientFactory.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab.http; 2 | 3 | import okhttp3.OkHttpClient; 4 | 5 | import javax.net.ssl.SSLContext; 6 | import javax.net.ssl.SSLSocketFactory; 7 | import java.security.KeyManagementException; 8 | import java.security.NoSuchAlgorithmException; 9 | import java.security.SecureRandom; 10 | 11 | public class HttpClientFactory { 12 | private static HttpClientFactory instance = new HttpClientFactory(); 13 | 14 | private HttpClientFactory() { 15 | // prohibit external creation 16 | } 17 | 18 | public static HttpClientFactory getInstance() { 19 | return instance; 20 | } 21 | 22 | public OkHttpClient getHttpClient() { 23 | return new OkHttpClient(); 24 | } 25 | 26 | public OkHttpClient getInsecureHttpClient() { 27 | try { 28 | SSLContext sslContext = SSLContext.getInstance("SSL"); 29 | sslContext.init(null, InsecureTrustManager.asList(), new SecureRandom()); 30 | SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); 31 | 32 | return new OkHttpClient.Builder() 33 | .sslSocketFactory(sslSocketFactory, InsecureTrustManager.INSTANCE) 34 | .hostnameVerifier((s, sslSession) -> true) 35 | .build(); 36 | } catch (NoSuchAlgorithmException | KeyManagementException e) { 37 | throw new HttpClientException("Cannot create insecure HTTP client: " + e.getMessage(), e); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/http/InsecureTrustManager.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab.http; 2 | 3 | import javax.net.ssl.TrustManager; 4 | import javax.net.ssl.X509TrustManager; 5 | import java.security.cert.X509Certificate; 6 | 7 | /** 8 | * A trust manager that does not validate certificate chains. 9 | */ 10 | public class InsecureTrustManager implements X509TrustManager { 11 | public static final InsecureTrustManager INSTANCE = new InsecureTrustManager(); 12 | 13 | private InsecureTrustManager() { 14 | // empty constructor 15 | } 16 | 17 | public static TrustManager[] asList() { 18 | return new TrustManager[]{INSTANCE}; 19 | } 20 | 21 | @Override 22 | public void checkClientTrusted(X509Certificate[] x509Certificates, String s) { 23 | // noop 24 | } 25 | 26 | @Override 27 | public void checkServerTrusted(X509Certificate[] x509Certificates, String s) { 28 | // noop 29 | } 30 | 31 | @Override 32 | public X509Certificate[] getAcceptedIssuers() { 33 | return new X509Certificate[0]; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/quickmr/AlwaysConfirmCreateMergeRequestAction.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab.quickmr; 2 | 3 | import com.github.novotnyr.idea.gitlab.MergeRequestRequest; 4 | import com.github.novotnyr.idea.gitlab.quickmr.settings.Settings; 5 | import com.intellij.openapi.actionSystem.AnActionEvent; 6 | import com.intellij.openapi.project.Project; 7 | import org.jetbrains.annotations.Nullable; 8 | 9 | import javax.swing.Icon; 10 | import java.util.concurrent.CompletableFuture; 11 | 12 | public class AlwaysConfirmCreateMergeRequestAction extends CreateMergeRequestAction { 13 | public AlwaysConfirmCreateMergeRequestAction() { 14 | } 15 | 16 | public AlwaysConfirmCreateMergeRequestAction(Icon icon) { 17 | super(icon); 18 | } 19 | 20 | public AlwaysConfirmCreateMergeRequestAction(@Nullable String text) { 21 | super(text); 22 | } 23 | 24 | public AlwaysConfirmCreateMergeRequestAction(@Nullable String text, @Nullable String description, @Nullable Icon icon) { 25 | super(text, description, icon); 26 | } 27 | 28 | @Override 29 | protected CompletableFuture validate(MergeRequestRequest request, SelectedModule module, Settings settings) { 30 | return showConfirmationDialog(request, module); 31 | } 32 | 33 | @Override 34 | public void update(AnActionEvent e) { 35 | Project project = e.getProject(); 36 | if (project == null) { 37 | return; 38 | } 39 | Settings settings = project.getService(Settings.class); 40 | e.getPresentation().setEnabledAndVisible(!settings.isAssigneesEnabled() && !settings.isEnableMergeRequestToFavoriteAssignee()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/quickmr/ConfirmMergeRequestDialog.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 |
124 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/quickmr/ConfirmMergeRequestDialog.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab.quickmr; 2 | 3 | import com.github.novotnyr.idea.git.GitService; 4 | import com.github.novotnyr.idea.gitlab.MergeRequestRequest; 5 | import com.github.novotnyr.idea.gitlab.User; 6 | import com.github.novotnyr.idea.gitlab.quickmr.settings.Settings; 7 | import com.intellij.openapi.progress.ProgressIndicator; 8 | import com.intellij.openapi.progress.Task; 9 | import com.intellij.openapi.ui.DialogWrapper; 10 | import com.intellij.openapi.ui.ValidationInfo; 11 | import com.intellij.ui.CollectionComboBoxModel; 12 | import com.intellij.ui.ListCellRendererWrapper; 13 | import com.intellij.ui.components.JBTextField; 14 | import git4idea.GitLocalBranch; 15 | import org.jetbrains.annotations.NotNull; 16 | import org.jetbrains.annotations.Nullable; 17 | 18 | import javax.swing.DefaultComboBoxModel; 19 | import javax.swing.JCheckBox; 20 | import javax.swing.JComboBox; 21 | import javax.swing.JComponent; 22 | import javax.swing.JLabel; 23 | import javax.swing.JList; 24 | import javax.swing.JPanel; 25 | import javax.swing.JTextArea; 26 | import javax.swing.JTextField; 27 | import java.util.List; 28 | import java.util.Objects; 29 | import java.util.Optional; 30 | import java.util.concurrent.CopyOnWriteArrayList; 31 | 32 | public class ConfirmMergeRequestDialog extends DialogWrapper { 33 | private static final boolean VERTICAL = true; 34 | 35 | private JPanel rootPanel; 36 | 37 | private JTextField titleTextField; 38 | private JComboBox targetBranchComboBox; 39 | private JComboBox assigneeComboBox; 40 | private JLabel sourceBranchLabel; 41 | private JTextArea descriptionTextArea; 42 | private JBTextField labelsTextField; 43 | private JCheckBox squashCommitsCheckBox; 44 | private JCheckBox deleteSourceBranchCheckBox; 45 | private JPanel hideableDescriptionPanel; 46 | 47 | private GitService gitService = new GitService(); 48 | 49 | public ConfirmMergeRequestDialog(MergeRequestRequest request, SelectedModule module) { 50 | super(true); 51 | init(); 52 | setTitle("Create Merge Request"); 53 | this.titleTextField.setText(request.getTitle()); 54 | this.descriptionTextArea.setText(request.getDescription()); 55 | this.sourceBranchLabel.setText(String.format("Merge from %s to", request.getSourceBranch())); 56 | 57 | this.labelsTextField.setText(request.getLabels()); 58 | this.labelsTextField.getEmptyText().setText("labels,are,comma,separated"); 59 | 60 | setTargetBranchComboBoxModel(request, module); 61 | setAssigneeComboBoxModel(request, module); 62 | 63 | this.squashCommitsCheckBox.setSelected(request.isSquash()); 64 | this.deleteSourceBranchCheckBox.setSelected(request.isRemoveSourceBranch()); 65 | } 66 | 67 | @Nullable 68 | @Override 69 | protected ValidationInfo doValidate() { 70 | if (this.titleTextField.getText().isEmpty()) { 71 | return new ValidationInfo("Merge Request title must be provided", this.titleTextField); 72 | } 73 | return super.doValidate(); 74 | } 75 | 76 | @Nullable 77 | @Override 78 | protected JComponent createCenterPanel() { 79 | return this.rootPanel; 80 | } 81 | 82 | @Nullable 83 | @Override 84 | protected String getDimensionServiceKey() { 85 | return getClass().getName(); 86 | } 87 | 88 | public String getMergeRequestTitle() { 89 | return this.titleTextField.getText(); 90 | } 91 | 92 | public Optional getMergeRequestDescription() { 93 | String text = this.descriptionTextArea.getText(); 94 | if (text == null || text.isEmpty()) { 95 | return Optional.empty(); 96 | } else { 97 | return Optional.of(text); 98 | } 99 | } 100 | 101 | public Optional getMergeRequestLabels() { 102 | String text = this.labelsTextField.getText(); 103 | if (text == null || text.isEmpty()) { 104 | return Optional.empty(); 105 | } else { 106 | return Optional.of(text); 107 | } 108 | } 109 | 110 | public String getTargetBranch() { 111 | return (String) this.targetBranchComboBox.getSelectedItem(); 112 | } 113 | 114 | public Optional getAssignee() { 115 | User assignee = (User) this.assigneeComboBox.getSelectedItem(); 116 | if (User.NONE.equals(assignee)) { 117 | return Optional.empty(); 118 | } 119 | return Optional.ofNullable(assignee); 120 | } 121 | 122 | private void setTargetBranchComboBoxModel(MergeRequestRequest request, SelectedModule module) { 123 | Task.Modal task = new Task.Modal(module.getProject(), "Retrieving Git branch info", true) { 124 | final List localBranches = new CopyOnWriteArrayList<>(); 125 | 126 | @Override 127 | public void run(@NotNull ProgressIndicator indicator) { 128 | GitService git = ConfirmMergeRequestDialog.this.gitService; 129 | for (GitLocalBranch localBranch : git.getLocalBranches(module.getProject(), module.getFile())) { 130 | localBranches.add(localBranch.getName()); 131 | } 132 | } 133 | 134 | @Override 135 | public void onSuccess() { 136 | JComboBox component = ConfirmMergeRequestDialog.this.targetBranchComboBox; 137 | component.setModel(new CollectionComboBoxModel<>(localBranches, request.getTargetBranch())); 138 | } 139 | }; 140 | task.queue(); 141 | } 142 | 143 | private void setAssigneeComboBoxModel(MergeRequestRequest request, SelectedModule module) { 144 | DefaultComboBoxModel model = new DefaultComboBoxModel<>(); 145 | Settings settings = module.getProject().getService(Settings.class); 146 | model.addElement(User.NONE); 147 | User implicitAssignee = User.NONE; 148 | for (User defaultAssignee : settings.getDefaultAssignees()) { 149 | model.addElement(defaultAssignee); 150 | if (Objects.equals(request.getAssigneeId(), defaultAssignee.getId())) { 151 | implicitAssignee = defaultAssignee; 152 | } 153 | } 154 | this.assigneeComboBox.setModel(model); 155 | this.assigneeComboBox.setSelectedItem(implicitAssignee); 156 | this.assigneeComboBox.setRenderer(new ListCellRendererWrapper<>() { 157 | @Override 158 | public void customize(JList list, User user, int index, boolean selected, boolean hasFocus) { 159 | if (User.NONE.equals(user)) { 160 | setText("- none -"); 161 | return; 162 | } 163 | String renderedText = user.getName() + " (" + user.getUsername() + ")"; 164 | setText(renderedText); 165 | } 166 | }); 167 | } 168 | 169 | public boolean isSourceBranchDeletedOnAccept() { 170 | return this.deleteSourceBranchCheckBox.isSelected(); 171 | } 172 | } 173 | 174 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/quickmr/CreateMergeRequestAction.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab.quickmr; 2 | 3 | import com.github.novotnyr.idea.git.GitService; 4 | import com.github.novotnyr.idea.gitlab.AccessDeniedException; 5 | import com.github.novotnyr.idea.gitlab.DuplicateMergeRequestException; 6 | import com.github.novotnyr.idea.gitlab.MergeRequestRequest; 7 | import com.github.novotnyr.idea.gitlab.MergeRequestResponse; 8 | import com.github.novotnyr.idea.gitlab.User; 9 | import com.github.novotnyr.idea.gitlab.quickmr.settings.Settings; 10 | import com.github.novotnyr.idea.gitlab.quickmr.settings.SettingsUi; 11 | import com.intellij.ide.browsers.BrowserLauncher; 12 | import com.intellij.notification.Notification; 13 | import com.intellij.notification.NotificationListener; 14 | import com.intellij.notification.NotificationType; 15 | import com.intellij.notification.Notifications; 16 | import com.intellij.openapi.actionSystem.AnAction; 17 | import com.intellij.openapi.actionSystem.AnActionEvent; 18 | import com.intellij.openapi.application.ApplicationManager; 19 | import com.intellij.openapi.application.ModalityState; 20 | import com.intellij.openapi.components.ServiceManager; 21 | import com.intellij.openapi.options.ShowSettingsUtil; 22 | import com.intellij.openapi.project.Project; 23 | import com.intellij.openapi.util.text.Strings; 24 | import com.intellij.util.ModalityUiUtil; 25 | import com.intellij.util.concurrency.annotations.RequiresBackgroundThread; 26 | import org.jetbrains.annotations.NotNull; 27 | import org.jetbrains.annotations.Nullable; 28 | 29 | import javax.swing.Icon; 30 | import java.net.URI; 31 | import java.net.URISyntaxException; 32 | import java.util.Optional; 33 | import java.util.concurrent.CompletableFuture; 34 | import java.util.concurrent.CompletionException; 35 | 36 | import static java.util.concurrent.CompletableFuture.completedFuture; 37 | 38 | public class CreateMergeRequestAction extends AnAction { 39 | private final GitService gitService = ServiceManager.getService(GitService.class); 40 | private User assignee; 41 | 42 | public CreateMergeRequestAction() { 43 | } 44 | 45 | public CreateMergeRequestAction(Icon icon) { 46 | super(icon); 47 | } 48 | 49 | public CreateMergeRequestAction(@Nullable String text) { 50 | super(text); 51 | } 52 | 53 | public CreateMergeRequestAction(@Nullable String text, @Nullable String description, @Nullable Icon icon) { 54 | super(text, description, icon); 55 | } 56 | 57 | @Override 58 | public void actionPerformed(@NotNull AnActionEvent event) { 59 | SelectedModule selectedModule = SelectedModule.fromEvent(event); 60 | if (selectedModule == null) { 61 | return; 62 | } 63 | getProjectName(selectedModule).thenAccept(gitLabProjectId -> { 64 | createMergeRequestAsync(selectedModule, gitLabProjectId); 65 | }); 66 | } 67 | 68 | @RequiresBackgroundThread 69 | private void createMergeRequestAsync(SelectedModule selectedModule, String gitLabProjectId) { 70 | Project project = selectedModule.getProject(); 71 | try { 72 | Settings settings = project.getService(Settings.class); 73 | 74 | PlaceholderResolver placeholderResolver = new PlaceholderResolver(this.gitService, project, settings); 75 | MergeRequestService mergeRequestService = new MergeRequestService(this.gitService, placeholderResolver); 76 | NewMergeRequest mergeRequest = new NewMergeRequest(); 77 | mergeRequest.setAssignee(this.assignee); 78 | mergeRequest.setGitLabProjectId(gitLabProjectId); 79 | mergeRequest.setSourceBranch(getSourceBranch(selectedModule)); 80 | 81 | MergeRequestRequest request = mergeRequestService.prepare(mergeRequest, settings); 82 | validate(request, selectedModule, settings) 83 | .thenCompose(__ -> mergeRequestService.submit(mergeRequest.getGitLabProjectId(), request, settings)) 84 | .thenAccept(mergeRequestResponse -> createNotification(mergeRequestResponse, project, gitLabProjectId, settings)) 85 | .exceptionally(this::createErrorNotification); 86 | 87 | } catch (SourceAndTargetBranchCannotBeEqualException e) { 88 | this.createErrorNotification(e); 89 | } catch (SettingsNotInitializedException e) { 90 | var mrNotConfigured = new Notification("GitLab Merge Request", 91 | "Quick Merge Request are not configured", 92 | "Quick Merge Requests are not configured
Configure", 93 | NotificationType.INFORMATION) 94 | .setListener((notification, evt) -> { 95 | ShowSettingsUtil.getInstance().showSettingsDialog(project, SettingsUi.class); 96 | notification.expire(); 97 | }); 98 | Notifications.Bus.notify(mrNotConfigured); 99 | } 100 | } 101 | 102 | // Runs on nonEDT 103 | protected CompletableFuture validate(MergeRequestRequest request, SelectedModule module, Settings settings) { 104 | if (!settings.isShowConfirmationDialog()) { 105 | return completedFuture(true); 106 | } else { 107 | return showConfirmationDialog(request, module); 108 | } 109 | } 110 | 111 | protected CompletableFuture showConfirmationDialog(MergeRequestRequest request, SelectedModule module) { 112 | CompletableFuture result = new CompletableFuture<>(); 113 | ModalityUiUtil.invokeLaterIfNeeded(ModalityState.defaultModalityState(), () -> { 114 | if (!isAcceptedByUser(request, module)) { 115 | result.completeExceptionally(new RequestCannotBeSubmittedException()); 116 | } else { 117 | result.complete(true); 118 | } 119 | }); 120 | return result; 121 | } 122 | 123 | private boolean isAcceptedByUser(MergeRequestRequest request, SelectedModule module) { 124 | ConfirmMergeRequestDialog dialog = new ConfirmMergeRequestDialog(request, module); 125 | if (!dialog.showAndGet()) { 126 | return false; 127 | } 128 | request.setTargetBranch(dialog.getTargetBranch()); 129 | request.setTitle(dialog.getMergeRequestTitle()); 130 | request.setRemoveSourceBranch(dialog.isSourceBranchDeletedOnAccept()); 131 | dialog.getMergeRequestDescription().ifPresent(request::setDescription); 132 | dialog.getMergeRequestLabels().ifPresent(request::setLabels); 133 | Optional maybeAssignee = dialog.getAssignee(); 134 | if (maybeAssignee.isPresent()) { 135 | maybeAssignee 136 | .map(User::getId) 137 | .ifPresent(request::setAssigneeId); 138 | } else { 139 | request.setAssigneeId(null); 140 | } 141 | return true; 142 | } 143 | 144 | @Override 145 | public void update(AnActionEvent e) { 146 | Project project = e.getProject(); 147 | if (project == null) { 148 | return; 149 | } 150 | Settings settings = project.getService(Settings.class); 151 | if (this.assignee == null) { 152 | // assignee will be deduced from settings, enable according to preferences 153 | e.getPresentation().setEnabledAndVisible(settings.isEnableMergeRequestToFavoriteAssignee()); 154 | return; 155 | } 156 | e.getPresentation().setEnabledAndVisible(true); 157 | } 158 | 159 | private CompletableFuture getProjectName(SelectedModule selectedModule) { 160 | CompletableFuture result = new CompletableFuture<>(); 161 | ApplicationManager.getApplication().executeOnPooledThread(() -> { 162 | try { 163 | String projectGitUrl = this.gitService.getProjectGitUrl(selectedModule); 164 | if (projectGitUrl == null) { 165 | return; 166 | } 167 | String gitLabProjectId = this.gitService.getRepoPathWithoutDotGit(projectGitUrl); 168 | result.complete(gitLabProjectId); 169 | } catch (Exception e) { 170 | result.completeExceptionally(e); 171 | } 172 | }); 173 | return result; 174 | } 175 | 176 | @NotNull 177 | private String getSourceBranch(SelectedModule selectedModule) { 178 | return this.gitService.getCurrentBranch(selectedModule); 179 | } 180 | 181 | private void createNotification(MergeRequestResponse mergeRequestResponse, Project project, String projectName, Settings settings) { 182 | String number = mergeRequestResponse.getNumber(); 183 | String assignee = mergeRequestResponse.getAssigneeName(); 184 | String assigneeMessage; 185 | if (assignee != null) { 186 | assigneeMessage = "Assigned in " + projectName + " to " + assignee + "

"; 187 | } else { 188 | assigneeMessage = "Created in " + projectName + "

"; 189 | } 190 | 191 | 192 | String title = "Merge Request #" + number + " Created"; 193 | 194 | NotificationListener notificationListener = (notification, event) -> {}; 195 | String webUrl = mergeRequestResponse.getWebUrl(); 196 | if (Strings.isNotEmpty(webUrl)) { 197 | assigneeMessage += "View in GitLab"; 198 | notificationListener = (notification, hyperlinkEvent) -> { 199 | try { 200 | BrowserLauncher.getInstance().browse(new URI(webUrl)); 201 | } catch (URISyntaxException e) { 202 | e.printStackTrace(); 203 | } 204 | }; 205 | } 206 | 207 | var notification = new Notification("GitLab Merge Request", title, 208 | assigneeMessage, NotificationType.INFORMATION) 209 | .setListener(notificationListener); 210 | Notifications.Bus.notify(notification); 211 | } 212 | 213 | private Void createErrorNotification(Throwable t) { 214 | String title = "Merge Request Failed"; 215 | String messagePrefix = "Failed to create merge request: "; 216 | Throwable exception = unwrapCompletionException(t); 217 | String message = messagePrefix + exception.getMessage(); 218 | NotificationType notificationType = null; 219 | if (exception instanceof RequestCannotBeSubmittedException) { 220 | // user cancelled 221 | return null; 222 | } 223 | if (exception instanceof DuplicateMergeRequestException) { 224 | title = "Merge Request Already Exists"; 225 | message = "Merge Request has already been submitted"; 226 | notificationType = NotificationType.WARNING; 227 | } 228 | if (exception instanceof AccessDeniedException) { 229 | title = "GitLab Access Denied"; 230 | message = "Please check Access Token in Preferences."; 231 | notificationType = NotificationType.ERROR; 232 | } 233 | 234 | Notification notification = new Notification("GitLab Merge Request", title, message, notificationType); 235 | 236 | Notifications.Bus.notify(notification); 237 | return null; 238 | } 239 | 240 | private Throwable unwrapCompletionException(Throwable t) { 241 | return t instanceof CompletionException ? t.getCause() : t; 242 | } 243 | 244 | public void setAssignee(User assignee) { 245 | this.assignee = assignee; 246 | } 247 | 248 | private static class RequestCannotBeSubmittedException extends RuntimeException { 249 | // empty body 250 | } 251 | 252 | } 253 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/quickmr/CreateMergeRequestAndAssignToActionGroup.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab.quickmr; 2 | 3 | import com.github.novotnyr.idea.gitlab.User; 4 | import com.github.novotnyr.idea.gitlab.quickmr.settings.Settings; 5 | import com.intellij.openapi.actionSystem.ActionGroup; 6 | import com.intellij.openapi.actionSystem.AnAction; 7 | import com.intellij.openapi.actionSystem.AnActionEvent; 8 | import com.intellij.openapi.project.Project; 9 | import org.jetbrains.annotations.Nullable; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | public class CreateMergeRequestAndAssignToActionGroup extends ActionGroup { 15 | public CreateMergeRequestAndAssignToActionGroup() { 16 | super("Quick Merge Request Assigned to", true); 17 | } 18 | 19 | public AnAction[] getChildren(@Nullable AnActionEvent anActionEvent) { 20 | if (anActionEvent == null) { 21 | return new AnAction[0]; 22 | } 23 | Project project = anActionEvent.getProject(); 24 | if (project == null) { 25 | return new AnAction[0]; 26 | } 27 | Settings settings = project.getService(Settings.class); 28 | 29 | List actions = new ArrayList<>(); 30 | for (User assignee : settings.getDefaultAssignees()) { 31 | CreateMergeRequestAction action = new CreateMergeRequestAction("" + assignee.getName()); 32 | action.setAssignee(assignee); 33 | 34 | actions.add(action); 35 | } 36 | return actions.toArray(new AnAction[0]); 37 | } 38 | 39 | @Override 40 | public void update(AnActionEvent e) { 41 | Project project = e.getProject(); 42 | if (project == null) { 43 | return; 44 | } 45 | Settings settings = project.getService(Settings.class); 46 | e.getPresentation().setVisible(settings.isAssigneesEnabled()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/quickmr/IllegalGitLabUrlException.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab.quickmr; 2 | 3 | public class IllegalGitLabUrlException extends RuntimeException { 4 | 5 | public IllegalGitLabUrlException() { 6 | super(); 7 | } 8 | 9 | public IllegalGitLabUrlException(String msg) { 10 | super(msg); 11 | } 12 | 13 | public IllegalGitLabUrlException(String message, Throwable cause) { 14 | super(message, cause); 15 | } 16 | 17 | public IllegalGitLabUrlException(Throwable cause) { 18 | super(cause); 19 | } 20 | } -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/quickmr/JBProgressIndicator.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab.quickmr; 2 | 3 | import com.github.novotnyr.idea.gitlab.ProgressIndicator; 4 | import com.intellij.openapi.progress.ProgressManager; 5 | 6 | public class JBProgressIndicator implements ProgressIndicator { 7 | @Override 8 | public void setPercents(float percents) { 9 | com.intellij.openapi.progress.ProgressIndicator progressIndicator = ProgressManager.getInstance() 10 | .getProgressIndicator(); 11 | if (percents < 0f) { 12 | progressIndicator.setIndeterminate(true); 13 | } else { 14 | progressIndicator.setIndeterminate(false); 15 | progressIndicator.setFraction(percents); 16 | } 17 | 18 | } 19 | 20 | @Override 21 | public boolean isCancelled() { 22 | return ProgressManager.getInstance().getProgressIndicator().isCanceled(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/quickmr/MergeRequestService.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab.quickmr; 2 | 3 | import com.github.novotnyr.idea.git.GitService; 4 | import com.github.novotnyr.idea.gitlab.GitLab; 5 | import com.github.novotnyr.idea.gitlab.MergeRequestRequest; 6 | import com.github.novotnyr.idea.gitlab.MergeRequestResponse; 7 | import com.github.novotnyr.idea.gitlab.quickmr.settings.Settings; 8 | import org.jetbrains.annotations.NotNull; 9 | import org.jetbrains.annotations.Nullable; 10 | 11 | import java.util.Objects; 12 | import java.util.concurrent.CompletableFuture; 13 | 14 | public class MergeRequestService { 15 | private final GitService gitService; 16 | 17 | private final PlaceholderResolver placeholderResolver; 18 | 19 | public MergeRequestService(GitService gitService, PlaceholderResolver placeholderResolver) { 20 | this.gitService = gitService; 21 | this.placeholderResolver = placeholderResolver; 22 | } 23 | 24 | public MergeRequestRequest prepare(NewMergeRequest newMergeRequest, Settings settings) throws SourceAndTargetBranchCannotBeEqualException, SettingsNotInitializedException { 25 | if (!settings.isInitialized()) { 26 | throw new SettingsNotInitializedException(); 27 | } 28 | 29 | String sourceBranch = newMergeRequest.getSourceBranch(); 30 | String targetBranch = settings.getDefaultTargetBranch(); 31 | if (Objects.equals(sourceBranch, targetBranch)) { 32 | throw new SourceAndTargetBranchCannotBeEqualException(sourceBranch); 33 | } 34 | 35 | MergeRequestRequest request = new MergeRequestRequest(); 36 | request.setSourceBranch(sourceBranch); 37 | request.setTargetBranch(targetBranch); 38 | setAssignee(request, newMergeRequest, settings); 39 | setTitle(request, newMergeRequest, settings); 40 | setDescription(request, newMergeRequest, settings); 41 | setLabels(request, newMergeRequest, settings); 42 | request.setRemoveSourceBranch(settings.isRemoveSourceBranchOnMerge()); 43 | request.setSquash(settings.isSquashCommits()); 44 | return request; 45 | } 46 | 47 | public CompletableFuture submit(String gitLabProjectId, MergeRequestRequest mergeRequestRequest, Settings settings) throws SourceAndTargetBranchCannotBeEqualException { 48 | GitLab gitLab = createGitLab(settings); 49 | return gitLab.createMergeRequest(gitLabProjectId, mergeRequestRequest); 50 | } 51 | 52 | public CompletableFuture createMergeRequest(NewMergeRequest newMergeRequest, Settings settings) throws SourceAndTargetBranchCannotBeEqualException, SettingsNotInitializedException { 53 | MergeRequestRequest request = prepare(newMergeRequest, settings); 54 | return submit(newMergeRequest.getGitLabProjectId(), request, settings); 55 | } 56 | 57 | private void setTitle(MergeRequestRequest request, NewMergeRequest newMergeRequest, Settings settings) { 58 | String title = resolvePlaceHolders(request, newMergeRequest, settings.getDefaultTitle(), settings); 59 | if (title != null) { 60 | request.setTitle(title); 61 | } 62 | } 63 | 64 | private void setDescription(MergeRequestRequest request, NewMergeRequest newMergeRequest, Settings settings) { 65 | String description = resolvePlaceHolders(request, newMergeRequest, settings.getDefaultDescription(), settings); 66 | if (description != null) { 67 | request.setDescription(description); 68 | } 69 | } 70 | 71 | @Nullable 72 | private String resolvePlaceHolders(MergeRequestRequest request, NewMergeRequest newMergeRequest, String template, Settings settings) { 73 | if (template == null) { 74 | return null; 75 | } 76 | String resolvedTemplate = template; 77 | 78 | for (String placeHolder : PlaceholderResolver.PLACEHOLDERS) { 79 | resolvedTemplate = this.placeholderResolver.resolvePlaceholder(resolvedTemplate, placeHolder, newMergeRequest); 80 | } 81 | 82 | return resolvedTemplate; 83 | } 84 | 85 | private void setAssignee(MergeRequestRequest request, NewMergeRequest newMergeRequest, Settings settings) { 86 | if (settings.isAssigneesEnabled()) { 87 | if (newMergeRequest.getAssignee() == null) { 88 | request.setAssigneeId(settings.getDefaultAssigneeId()); 89 | } else { 90 | request.setAssigneeId(newMergeRequest.getAssignee().getId()); 91 | } 92 | } 93 | } 94 | 95 | private void setLabels(MergeRequestRequest request, NewMergeRequest newMergeRequest, Settings settings) { 96 | request.setLabels(settings.getDefaultLabels()); 97 | } 98 | 99 | 100 | @NotNull 101 | protected GitLab createGitLab(Settings settings) { 102 | return new GitLab(settings.getGitLabUri(), settings.getAccessToken(), settings.isInsecureTls()); 103 | } 104 | 105 | @NotNull 106 | private String getSourceBranch(SelectedModule selectedModule) { 107 | return this.gitService.getCurrentBranch(selectedModule); 108 | } 109 | 110 | 111 | } 112 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/quickmr/NewMergeRequest.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab.quickmr; 2 | 3 | import com.github.novotnyr.idea.gitlab.User; 4 | 5 | public class NewMergeRequest { 6 | private String gitLabProjectId; 7 | 8 | private String sourceBranch; 9 | 10 | private User assignee; 11 | 12 | public String getGitLabProjectId() { 13 | return gitLabProjectId; 14 | } 15 | 16 | public String getSourceBranch() { 17 | return sourceBranch; 18 | } 19 | 20 | public void setGitLabProjectId(String gitLabProjectId) { 21 | this.gitLabProjectId = gitLabProjectId; 22 | } 23 | 24 | public void setSourceBranch(String sourceBranch) { 25 | this.sourceBranch = sourceBranch; 26 | } 27 | 28 | public User getAssignee() { 29 | return assignee; 30 | } 31 | 32 | public void setAssignee(User assignee) { 33 | this.assignee = assignee; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/quickmr/PlaceholderResolver.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab.quickmr; 2 | 3 | import com.github.novotnyr.idea.git.GitService; 4 | import com.github.novotnyr.idea.gitlab.quickmr.settings.Settings; 5 | import com.intellij.openapi.project.Project; 6 | 7 | import java.util.Optional; 8 | 9 | public class PlaceholderResolver { 10 | public static final String LAST_COMMIT_MESSAGE_PLACEHOLDER = "lastCommitMessage"; 11 | public static final String LAST_COMMIT_MESSAGE_SUBJECT_PLACEHOLDER = "lastCommitMessageSubject"; 12 | public static final String LAST_COMMIT_MESSAGE_BODY_PLACEHOLDER = "lastCommitMessageBody"; 13 | public static final String SOURCE_BRANCH_PLACEHOLDER = "sourceBranch"; 14 | public static final String TARGET_BRANCH_PLACEHOLDER = "targetBranch"; 15 | 16 | public static final String[] PLACEHOLDERS = { 17 | LAST_COMMIT_MESSAGE_PLACEHOLDER, 18 | LAST_COMMIT_MESSAGE_SUBJECT_PLACEHOLDER, 19 | LAST_COMMIT_MESSAGE_BODY_PLACEHOLDER, 20 | SOURCE_BRANCH_PLACEHOLDER, 21 | TARGET_BRANCH_PLACEHOLDER 22 | }; 23 | 24 | private final GitService gitService; 25 | private final Project project; 26 | private final Settings settings; 27 | 28 | public PlaceholderResolver(GitService gitService, Project project, Settings settings) { 29 | this.gitService = gitService; 30 | this.project = project; 31 | this.settings = settings; 32 | } 33 | 34 | public String resolvePlaceholder(final String template, String placeholder, NewMergeRequest newMergeRequest) { 35 | String buffer = template; 36 | if (LAST_COMMIT_MESSAGE_PLACEHOLDER.equalsIgnoreCase(placeholder.trim())) { 37 | Optional maybeLastCommitMessage = gitService.getLastCommitMessage(this.project); 38 | if(maybeLastCommitMessage.isPresent()) { 39 | String lastCommitMessage = maybeLastCommitMessage.get(); 40 | buffer = buffer.replaceAll("\\{\\{lastCommitMessage}}", lastCommitMessage); 41 | } 42 | } 43 | if (LAST_COMMIT_MESSAGE_SUBJECT_PLACEHOLDER.equalsIgnoreCase(placeholder.trim())) { 44 | Optional subject = gitService.getLastCommitMessageSubject(this.project); 45 | if(subject.isPresent()) { 46 | buffer = buffer.replaceAll("\\{\\{lastCommitMessageSubject}}", subject.get()); 47 | } 48 | } 49 | if (LAST_COMMIT_MESSAGE_BODY_PLACEHOLDER.equalsIgnoreCase(placeholder.trim())) { 50 | Optional body = gitService.getLastCommitMessageBody(this.project); 51 | if(body.isPresent()) { 52 | buffer = buffer.replaceAll("\\{\\{lastCommitMessageBody}}", body.get()); 53 | } 54 | } 55 | if (SOURCE_BRANCH_PLACEHOLDER.equalsIgnoreCase(placeholder.trim())) { 56 | buffer = buffer.replaceAll("\\{\\{sourceBranch}}", newMergeRequest.getSourceBranch()); 57 | } 58 | if (TARGET_BRANCH_PLACEHOLDER.equalsIgnoreCase(placeholder.trim())) { 59 | buffer = buffer.replaceAll("\\{\\{targetBranch}}", settings.getDefaultTargetBranch()); 60 | } 61 | 62 | return buffer; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/quickmr/SelectedModule.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab.quickmr; 2 | 3 | import com.intellij.openapi.actionSystem.AnActionEvent; 4 | import com.intellij.openapi.actionSystem.CommonDataKeys; 5 | import com.intellij.openapi.project.Project; 6 | import com.intellij.openapi.vfs.VirtualFile; 7 | 8 | public class SelectedModule { 9 | private Project project; 10 | 11 | private VirtualFile file; 12 | 13 | public static SelectedModule fromEvent(AnActionEvent event) { 14 | Project project = event.getProject(); 15 | if (project == null) { 16 | return null; 17 | } 18 | VirtualFile file = event.getData(CommonDataKeys.VIRTUAL_FILE); 19 | if (file == null) { 20 | return null; 21 | } 22 | SelectedModule selectedModule = new SelectedModule(); 23 | selectedModule.file = file; 24 | selectedModule.project = project; 25 | return selectedModule; 26 | } 27 | 28 | public Project getProject() { 29 | return project; 30 | } 31 | 32 | public VirtualFile getFile() { 33 | return file; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/quickmr/SettingsNotInitializedException.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab.quickmr; 2 | 3 | public class SettingsNotInitializedException extends RuntimeException { 4 | 5 | public SettingsNotInitializedException() { 6 | super("Settings were not initialized in Configuration"); 7 | } 8 | 9 | } -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/quickmr/SourceAndTargetBranchCannotBeEqualException.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab.quickmr; 2 | 3 | public class SourceAndTargetBranchCannotBeEqualException extends RuntimeException { 4 | 5 | public SourceAndTargetBranchCannotBeEqualException(String branchName) { 6 | super("Source branch (" + branchName + ") and target branch must be different"); 7 | } 8 | } -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/quickmr/UserToStringConverter.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab.quickmr; 2 | 3 | import com.github.novotnyr.idea.gitlab.User; 4 | import com.intellij.util.Function; 5 | import org.jdesktop.swingx.renderer.StringValue; 6 | 7 | public class UserToStringConverter implements StringValue, Function { 8 | @Override 9 | public String getString(Object o) { 10 | if (o instanceof User) { 11 | User user = (User) o; 12 | StringBuilder resultString = new StringBuilder(); 13 | if (user.getName() != null) { 14 | resultString.append(user.getName()); 15 | } else { 16 | resultString.append(user.getId()); 17 | } 18 | String username = user.getUsername(); 19 | if (username != null && !username.trim().isEmpty()) { 20 | resultString.append(" (").append(username).append(")"); 21 | } 22 | return resultString.toString(); 23 | } 24 | return o.toString(); 25 | } 26 | 27 | @Override 28 | public String fun(Object o) { 29 | return getString(o); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/quickmr/settings/SelectAssigneeDialog.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 |
52 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/quickmr/settings/SelectAssigneeDialog.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab.quickmr.settings; 2 | 3 | import com.github.novotnyr.idea.gitlab.AbstractGitLabCommand; 4 | import com.github.novotnyr.idea.gitlab.GitLab; 5 | import com.github.novotnyr.idea.gitlab.User; 6 | import com.github.novotnyr.idea.gitlab.quickmr.JBProgressIndicator; 7 | import com.github.novotnyr.idea.gitlab.quickmr.UserToStringConverter; 8 | import com.intellij.openapi.progress.ProgressManager; 9 | import com.intellij.openapi.project.Project; 10 | import com.intellij.openapi.ui.DialogWrapper; 11 | import com.intellij.ui.CollectionListModel; 12 | import com.intellij.ui.ListSpeedSearch; 13 | import com.intellij.ui.components.JBList; 14 | import org.jdesktop.swingx.renderer.DefaultListRenderer; 15 | 16 | import javax.swing.JButton; 17 | import javax.swing.JComponent; 18 | import javax.swing.JLabel; 19 | import javax.swing.JPanel; 20 | import javax.swing.JTextField; 21 | import java.awt.event.ActionEvent; 22 | import java.util.List; 23 | import java.util.concurrent.CompletableFuture; 24 | import java.util.concurrent.atomic.AtomicReference; 25 | 26 | public class SelectAssigneeDialog extends DialogWrapper { 27 | private final Project project; 28 | private final GitLab gitLab; 29 | 30 | private JPanel innerPanel; 31 | private JTextField userTextField; 32 | private JButton searchButton; 33 | private JLabel userLabel; 34 | private JBList userListView; 35 | 36 | private CollectionListModel listModel = new CollectionListModel<>(); 37 | private UserToStringConverter userToStringConverter = new UserToStringConverter(); 38 | 39 | @SuppressWarnings("unchecked") 40 | public SelectAssigneeDialog(Project project, GitLab gitLab) { 41 | super(project, false); 42 | this.project = project; 43 | this.gitLab = gitLab; 44 | 45 | init(); 46 | 47 | this.userListView.setModel(this.listModel); 48 | this.userListView.setCellRenderer(new DefaultListRenderer(userToStringConverter)); 49 | new ListSpeedSearch(this.userListView, this.userToStringConverter); 50 | 51 | this.searchButton.addActionListener(this::onSearchButtonActionPerformed); 52 | 53 | getRootPane().setDefaultButton(this.searchButton); 54 | } 55 | 56 | public void onSearchButtonActionPerformed(ActionEvent event) { 57 | if (this.userTextField.getText() == null) { 58 | this.userListView.getEmptyText().setText("Username cannot be empty!"); 59 | return; 60 | } 61 | this.userListView.getEmptyText().setText(""); 62 | this.userListView.setPaintBusy(true); 63 | this.listModel.removeAll(); 64 | this.gitLab.searchUsers2(this.userTextField.getText(), 100, this::onProgressManager, new JBProgressIndicator()) 65 | .thenAccept(this::updateUsers) 66 | .exceptionally(t -> { 67 | this.userListView.getEmptyText().setText("Unable to load users"); 68 | this.userListView.setPaintBusy(false); 69 | return null; 70 | }); 71 | } 72 | 73 | private CompletableFuture onProgressManager(AbstractGitLabCommand command) { 74 | final AtomicReference> resultWrapper = new AtomicReference<>(); 75 | 76 | Runnable runnable = () -> resultWrapper.set(command.call()); 77 | try { 78 | ProgressManager.getInstance().runProcessWithProgressSynchronously(runnable, "Searching Users", true, this.project, this.getContentPanel()); 79 | return resultWrapper.get(); 80 | } catch (Exception e) { 81 | CompletableFuture exceptionalFuture = new CompletableFuture<>(); 82 | exceptionalFuture.completeExceptionally(e); 83 | return exceptionalFuture; 84 | } 85 | } 86 | 87 | private void updateUsers(List users) { 88 | this.listModel.replaceAll(users); 89 | this.userListView.setPaintBusy(false); 90 | } 91 | 92 | @Override 93 | protected JComponent createCenterPanel() { 94 | return this.innerPanel; 95 | } 96 | 97 | public User getAssignee() { 98 | return (User) this.userListView.getSelectedValue(); 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/quickmr/settings/SettingUtils.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab.quickmr.settings; 2 | 3 | import javax.swing.text.JTextComponent; 4 | import java.util.Collection; 5 | import java.util.HashSet; 6 | import java.util.Objects; 7 | import java.util.Set; 8 | 9 | public abstract class SettingUtils { 10 | public static boolean hasSameUniqueElements(Collection collection1, Collection collection2) { 11 | if (collection1 == collection2) { 12 | return true; 13 | } 14 | if (collection1 == null || collection2 == null) { 15 | return false; 16 | } 17 | Set set1 = new HashSet<>(collection1); 18 | Set set2 = new HashSet<>(collection2); 19 | return set1.equals(set2); 20 | } 21 | 22 | public static boolean equals(JTextComponent textComponent, String expectedValue) { 23 | String textValue = textComponent.getText(); 24 | if (textValue == null) { 25 | textValue = ""; 26 | } 27 | String expected = expectedValue; 28 | if (expected == null) { 29 | expected = ""; 30 | } 31 | return Objects.equals(textValue, expected); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/quickmr/settings/Settings.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab.quickmr.settings; 2 | 3 | import com.github.novotnyr.idea.gitlab.User; 4 | import com.intellij.credentialStore.CredentialAttributes; 5 | import com.intellij.credentialStore.Credentials; 6 | import com.intellij.ide.passwordSafe.PasswordSafe; 7 | import com.intellij.openapi.components.PersistentStateComponent; 8 | import com.intellij.openapi.components.State; 9 | import com.intellij.openapi.components.Storage; 10 | import org.jetbrains.annotations.NotNull; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | @State(name = Settings.NAME, storages = @Storage("gitlab-quickmr.xml")) 16 | public class Settings implements PersistentStateComponent { 17 | public static final String NAME = "gitlab-quickmr"; 18 | 19 | private State state = new State(); 20 | 21 | @Override 22 | public State getState() { 23 | return this.state; 24 | } 25 | 26 | @Override 27 | public void loadState(@NotNull State state) { 28 | this.state = state; 29 | } 30 | 31 | public boolean isInitialized() { 32 | boolean initialized = this.state.gitLabUri != null 33 | && this.getAccessToken() != null 34 | && this.state.defaultTargetBranch != null 35 | && this.state.defaultTitle != null 36 | && this.state.defaultDescription != null 37 | && this.state.defaultLabels != null 38 | ; 39 | if(this.state.assigneesEnabled) { 40 | return initialized && (this.state.defaultAssignees != null && !this.state.defaultAssignees.isEmpty()); 41 | } 42 | return initialized; 43 | } 44 | 45 | public void reset() { 46 | this.state = new State(); 47 | } 48 | 49 | public String getDefaultTitle() { 50 | return this.state.defaultTitle; 51 | } 52 | 53 | public void setDefaultTitle(String defaultTitle) { 54 | this.state.defaultTitle = defaultTitle; 55 | } 56 | 57 | public String getDefaultDescription() { 58 | return this.state.defaultDescription; 59 | } 60 | 61 | public void setDefaultDescription(String description) { 62 | this.state.defaultDescription = description; 63 | } 64 | 65 | public User getDefaultAssignee() { 66 | if (this.state.defaultAssignees == null || this.state.defaultAssignees.isEmpty()) { 67 | return null; 68 | } 69 | return this.state.defaultAssignees.get(0); 70 | } 71 | 72 | public Long getDefaultAssigneeId() { 73 | User defaultAssignee = getDefaultAssignee(); 74 | if (defaultAssignee != null) { 75 | return defaultAssignee.getId(); 76 | } else { 77 | return null; 78 | } 79 | } 80 | 81 | public List getDefaultAssignees() { 82 | return this.state.defaultAssignees != null ? this.state.defaultAssignees : new ArrayList<>(); 83 | } 84 | 85 | public void setDefaultAssignees(List defaultAssignees) { 86 | this.state.defaultAssignees = defaultAssignees; 87 | } 88 | 89 | public boolean isSquashCommits() { 90 | return this.state.squashCommits; 91 | } 92 | 93 | public void setSquashCommits(boolean squashCommits) { 94 | this.state.squashCommits = squashCommits; 95 | } 96 | 97 | public String getGitLabUri() { 98 | return this.state.gitLabUri; 99 | } 100 | 101 | public void setGitLabUri(String gitLabUri) { 102 | this.state.gitLabUri = gitLabUri; 103 | } 104 | 105 | public String getAccessToken() { 106 | CredentialAttributes credentialAttributes = getCredentialAttributes(); 107 | if (credentialAttributes == null) { 108 | return null; 109 | } 110 | Credentials credentials = PasswordSafe.getInstance().get(credentialAttributes); 111 | if (credentials == null) { 112 | return null; 113 | } 114 | return credentials.getPasswordAsString(); 115 | } 116 | 117 | public void setAccessToken(String accessToken) { 118 | CredentialAttributes credentialAttributes = getCredentialAttributes(); 119 | if (credentialAttributes == null) { 120 | return; 121 | } 122 | PasswordSafe.getInstance().setPassword(credentialAttributes, accessToken); 123 | } 124 | 125 | public String getDefaultTargetBranch() { 126 | return this.state.defaultTargetBranch; 127 | } 128 | 129 | public void setDefaultTargetBranch(String defaultTargetBranch) { 130 | this.state.defaultTargetBranch = defaultTargetBranch; 131 | } 132 | 133 | public String getDefaultLabels() { 134 | return this.state.defaultLabels; 135 | } 136 | 137 | public void setDefaultLabels(String defaultLabels) { 138 | this.state.defaultLabels = defaultLabels; 139 | } 140 | 141 | public boolean isEnableMergeRequestToFavoriteAssignee() { 142 | return this.state.enableMergeRequestToFavoriteAssignee; 143 | } 144 | 145 | public void setEnableMergeRequestToFavoriteAssignee(boolean enableMergeRequestToFavoriteAssignee) { 146 | this.state.enableMergeRequestToFavoriteAssignee = enableMergeRequestToFavoriteAssignee; 147 | } 148 | 149 | public boolean isRemoveSourceBranchOnMerge() { 150 | return this.state.removeSourceBranchOnMerge; 151 | } 152 | 153 | public void setRemoveSourceBranchOnMerge(boolean removeSourceBranchOnMerge) { 154 | this.state.removeSourceBranchOnMerge = removeSourceBranchOnMerge; 155 | } 156 | 157 | public boolean isAssigneesEnabled() { 158 | return this.state.assigneesEnabled; 159 | } 160 | 161 | public void setAssigneesEnabled(boolean assigneesEnabled) { 162 | this.state.assigneesEnabled = assigneesEnabled; 163 | } 164 | 165 | public boolean isShowConfirmationDialog() { 166 | return this.state.showConfirmationDialog; 167 | } 168 | 169 | public void setShowConfirmationDialog(boolean showConfirmationDialog) { 170 | this.state.showConfirmationDialog = showConfirmationDialog; 171 | } 172 | 173 | public boolean isInsecureTls() { 174 | return this.state.insecureTls; 175 | } 176 | 177 | public void setInsecureTls(boolean insecureTls) { 178 | this.state.insecureTls = insecureTls; 179 | } 180 | 181 | 182 | private CredentialAttributes getCredentialAttributes() { 183 | if (getGitLabUri() == null) { 184 | return null; 185 | } 186 | String serviceName = NAME + "\t" + getGitLabUri(); 187 | String userName = getGitLabUri(); 188 | return new CredentialAttributes(serviceName, userName, this.getClass(), false); 189 | } 190 | 191 | public static class State { 192 | public String gitLabUri; 193 | 194 | public List defaultAssignees = new ArrayList<>(); 195 | 196 | public String defaultTargetBranch; 197 | 198 | public String defaultTitle; 199 | 200 | public String defaultDescription; 201 | 202 | public String defaultLabels; 203 | 204 | public boolean enableMergeRequestToFavoriteAssignee = true; 205 | 206 | public boolean removeSourceBranchOnMerge; 207 | 208 | public boolean squashCommits = false; 209 | 210 | public boolean assigneesEnabled = true; 211 | 212 | public boolean showConfirmationDialog = false; 213 | 214 | public boolean insecureTls; 215 | 216 | } 217 | } 218 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/quickmr/settings/SettingsUi.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | -------------------------------------------------------------------------------- /src/main/java/com/github/novotnyr/idea/gitlab/quickmr/settings/SettingsUi.java: -------------------------------------------------------------------------------- 1 | package com.github.novotnyr.idea.gitlab.quickmr.settings; 2 | 3 | import com.github.novotnyr.idea.gitlab.GitLab; 4 | import com.github.novotnyr.idea.gitlab.GitLabHttpResponseBody; 5 | import com.github.novotnyr.idea.gitlab.GitLabHttpResponseException; 6 | import com.github.novotnyr.idea.gitlab.User; 7 | import com.github.novotnyr.idea.gitlab.quickmr.IllegalGitLabUrlException; 8 | import com.google.gson.JsonSyntaxException; 9 | import com.intellij.icons.AllIcons; 10 | import com.intellij.ide.browsers.BrowserLauncher; 11 | import com.intellij.openapi.actionSystem.AnActionEvent; 12 | import com.intellij.openapi.application.ApplicationManager; 13 | import com.intellij.openapi.application.ModalityState; 14 | import com.intellij.openapi.application.ex.ApplicationManagerEx; 15 | import com.intellij.openapi.options.Configurable; 16 | import com.intellij.openapi.options.ConfigurationException; 17 | import com.intellij.openapi.project.Project; 18 | import com.intellij.openapi.ui.MessageType; 19 | import com.intellij.openapi.ui.popup.Balloon; 20 | import com.intellij.openapi.ui.popup.JBPopupFactory; 21 | import com.intellij.openapi.vcs.VcsConfigurableProvider; 22 | import com.intellij.ui.AnActionButton; 23 | import com.intellij.ui.CollectionListModel; 24 | import com.intellij.ui.ToolbarDecorator; 25 | import com.intellij.ui.awt.RelativePoint; 26 | import com.intellij.ui.components.JBList; 27 | import com.intellij.ui.components.JBPasswordField; 28 | import com.intellij.ui.components.JBTextField; 29 | import com.intellij.util.concurrency.annotations.RequiresEdt; 30 | import okhttp3.HttpUrl; 31 | import org.apache.commons.lang.StringUtils; 32 | import org.apache.http.client.HttpResponseException; 33 | import org.jetbrains.annotations.Nls; 34 | import org.jetbrains.annotations.Nullable; 35 | 36 | import javax.net.ssl.SSLPeerUnverifiedException; 37 | import javax.swing.DefaultListCellRenderer; 38 | import javax.swing.JButton; 39 | import javax.swing.JCheckBox; 40 | import javax.swing.JComponent; 41 | import javax.swing.JLabel; 42 | import javax.swing.JList; 43 | import javax.swing.JPanel; 44 | import javax.swing.JTextArea; 45 | import java.awt.BorderLayout; 46 | import java.awt.Component; 47 | import java.awt.event.ActionEvent; 48 | import java.awt.event.ItemEvent; 49 | import java.net.URI; 50 | import java.util.ArrayList; 51 | import java.util.List; 52 | import java.util.concurrent.CompletionException; 53 | import java.util.function.Consumer; 54 | 55 | public class SettingsUi implements Configurable { 56 | private final Project project; 57 | private final BrowserLauncher browserLauncher; 58 | 59 | private JBTextField urlTextField; 60 | private JBPasswordField accessTokenTextField; 61 | private JBTextField targetBranchTextField; 62 | private JBTextField mergeRequestTitleTextField; 63 | private JButton validateServerButton; 64 | private JLabel defaultAssigneeLabel; 65 | private JBList assigneeList; 66 | private JPanel assigneeListPlaceHolder; 67 | private JPanel rootPanel; 68 | private JCheckBox enableDefaultAssigneeActionCheckBox; 69 | private JCheckBox removeSourceBranchCheckbox; 70 | private JCheckBox enableAssigneesCheckBox; 71 | private JButton openAccessTokenUrlButton; 72 | private JCheckBox showConfirmationDialogCheckBox; 73 | private JCheckBox insecureTLSCheckBox; 74 | private JTextArea mergeRequestDescriptionTextArea; 75 | private JBTextField labelsTextField; 76 | private JCheckBox squashCommitsCheckBox; 77 | 78 | private CollectionListModel assigneeListModel = new CollectionListModel<>(); 79 | 80 | private Settings settings; 81 | 82 | private boolean serverUrlValidated = true; 83 | 84 | /** 85 | * Cached hashcode of access token to speed up isModified() 86 | */ 87 | private int accessTokenHashCode; 88 | 89 | public SettingsUi(Project project) { 90 | this.project = project; 91 | this.browserLauncher = BrowserLauncher.getInstance(); 92 | 93 | this.urlTextField.getEmptyText().setText("https://gitlab.com/api/v4"); 94 | 95 | this.openAccessTokenUrlButton.setIcon(AllIcons.General.Web); 96 | 97 | this.assigneeList = new JBList<>(); 98 | this.assigneeList.setModel(this.assigneeListModel); 99 | this.assigneeList.setCellRenderer(new DefaultListCellRenderer() { 100 | @Override 101 | public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 102 | User user = (User) value; 103 | String renderedText = user.getName() + " (" + user.getUsername() + ")"; 104 | if (index == 0) { 105 | Component component = super.getListCellRendererComponent(list, renderedText, index, isSelected, cellHasFocus); 106 | if (component instanceof JLabel) { 107 | JLabel label = (JLabel) component; 108 | label.setIcon(AllIcons.Toolwindows.ToolWindowFavorites); 109 | return label; 110 | } 111 | } 112 | return super.getListCellRendererComponent(list, renderedText, index, isSelected, cellHasFocus); 113 | } 114 | }); 115 | 116 | this.assigneeListPlaceHolder.setLayout(new BorderLayout()); 117 | this.assigneeListPlaceHolder.add( 118 | ToolbarDecorator 119 | .createDecorator(this.assigneeList) 120 | .setAddAction(this::onAddAssignee) 121 | .setAddActionUpdater(this::isAddAssigneeEnabled) 122 | .setRemoveAction(this::onRemoveAssignee) 123 | .createPanel() 124 | ); 125 | 126 | this.labelsTextField.getEmptyText().setText("labels are comma separated"); 127 | 128 | this.validateServerButton.addActionListener(this::onValidateServerButtonClicked); 129 | 130 | this.enableAssigneesCheckBox.addItemListener(this::onDisableAssigneesItemStateChanged); 131 | 132 | this.openAccessTokenUrlButton.addActionListener(this::onOpenAccessTokenUrlButtonClicked); 133 | } 134 | 135 | private void bindToComponents(Settings settings) { 136 | this.urlTextField.setText(settings.getGitLabUri()); 137 | this.accessTokenTextField.setText(settings.getAccessToken()); 138 | this.targetBranchTextField.setText(settings.getDefaultTargetBranch()); 139 | this.mergeRequestTitleTextField.setText(settings.getDefaultTitle()); 140 | this.mergeRequestDescriptionTextArea.setText(settings.getDefaultDescription()); 141 | this.labelsTextField.setText(settings.getDefaultLabels()); 142 | this.assigneeListModel.replaceAll(settings.getDefaultAssignees()); 143 | this.enableDefaultAssigneeActionCheckBox.setSelected(settings.isEnableMergeRequestToFavoriteAssignee()); 144 | this.removeSourceBranchCheckbox.setSelected(settings.isRemoveSourceBranchOnMerge()); 145 | this.squashCommitsCheckBox.setSelected(settings.isSquashCommits()); 146 | this.enableAssigneesCheckBox.setSelected(settings.isAssigneesEnabled()); 147 | this.assigneeList.setEnabled(settings.isAssigneesEnabled()); 148 | this.enableDefaultAssigneeActionCheckBox.setEnabled(settings.isAssigneesEnabled()); 149 | this.showConfirmationDialogCheckBox.setSelected(settings.isShowConfirmationDialog()); 150 | this.insecureTLSCheckBox.setSelected(settings.isInsecureTls()); 151 | } 152 | 153 | private void onValidateServerButtonClicked(ActionEvent event) { 154 | if (StringUtils.isEmpty(this.urlTextField.getText())) { 155 | warnInvalidServer(new IllegalGitLabUrlException("GitLab URL cannot be empty")); 156 | return; 157 | } 158 | 159 | GitLab gitLab = new GitLab(this.urlTextField.getText(), String.valueOf(accessTokenTextField.getPassword()), insecureTLSCheckBox.isSelected()); 160 | gitLab.version().thenRun(() -> { 161 | JBPopupFactory.getInstance() 162 | .createHtmlTextBalloonBuilder("GitLab connection successful", MessageType.INFO, null) 163 | .setFadeoutTime(7500) 164 | .createBalloon() 165 | .show(RelativePoint.getNorthWestOf(this.validateServerButton), 166 | Balloon.Position.atRight); 167 | 168 | }) 169 | .exceptionally(t -> { 170 | warnInvalidServer(t); 171 | return null; 172 | }); 173 | } 174 | 175 | 176 | private void onDisableAssigneesItemStateChanged(ItemEvent event) { 177 | switch (event.getStateChange()) { 178 | case ItemEvent.SELECTED: 179 | this.assigneeList.setEnabled(true); 180 | this.enableDefaultAssigneeActionCheckBox.setEnabled(true); 181 | break; 182 | case ItemEvent.DESELECTED: 183 | this.assigneeList.setEnabled(false); 184 | this.enableDefaultAssigneeActionCheckBox.setEnabled(false); 185 | break; 186 | } 187 | } 188 | 189 | public JPanel getRootPanel() { 190 | return rootPanel; 191 | } 192 | 193 | private void onOpenAccessTokenUrlButtonClicked(ActionEvent e) { 194 | String url = this.urlTextField.getText(); 195 | if (HttpUrl.parse(url) == null) { 196 | warnInvalidServer(new IllegalGitLabUrlException("Incorrect format of GitLab URL")); 197 | } else { 198 | String baseUrl = GitLab.getBaseUrl(url); 199 | String accessTokenUrl = GitLab.getAccessTokenWebPageUrl(baseUrl); 200 | this.browserLauncher.browse(URI.create(accessTokenUrl)); 201 | } 202 | } 203 | 204 | //------- 205 | 206 | @RequiresEdt 207 | private void showAndGetAssignee(GitLab gitLab, Consumer onAvailableAssigneeConsumer) { 208 | SelectAssigneeDialog dialog = new SelectAssigneeDialog(this.project, gitLab); 209 | if (!dialog.showAndGet()) { 210 | return; 211 | } 212 | User assignee = dialog.getAssignee(); 213 | if (assignee == null) { 214 | return; 215 | } 216 | onAvailableAssigneeConsumer.accept(assignee); 217 | } 218 | 219 | public void onAddAssignee(AnActionButton anActionButton) { 220 | GitLab gitLab = new GitLab(this.urlTextField.getText(), String.valueOf(accessTokenTextField.getPassword()), insecureTLSCheckBox.isSelected()); 221 | gitLab.version().thenRun(() -> { 222 | ApplicationManagerEx.getApplicationEx().invokeLater(() -> { 223 | showAndGetAssignee(gitLab, this.assigneeListModel::add); 224 | }, ModalityState.any()); 225 | }) 226 | .exceptionally(t -> { 227 | ApplicationManager.getApplication().invokeLater(() -> warnInvalidServer(t)); 228 | return null; 229 | }); 230 | } 231 | 232 | private boolean isAddAssigneeEnabled(AnActionEvent event) { 233 | return StringUtils.isNotEmpty(this.urlTextField.getText()); 234 | } 235 | 236 | private void onRemoveAssignee(AnActionButton anActionButton) { 237 | int selectedIndex = this.assigneeList.getSelectedIndex(); 238 | if (selectedIndex >= 0) { 239 | this.assigneeListModel.remove(selectedIndex); 240 | } 241 | } 242 | 243 | public List validate() { 244 | List validationErrors = new ArrayList<>(); 245 | if (!StringUtils.isNotEmpty(this.urlTextField.getText())) { 246 | validationErrors.add("Missing GitLab URI"); 247 | } 248 | if (!StringUtils.isNotEmpty(this.targetBranchTextField.getText())) { 249 | validationErrors.add("Missing default target branch"); 250 | } 251 | if (!StringUtils.isNotEmpty(this.mergeRequestTitleTextField.getText())) { 252 | validationErrors.add("Missing default Merge Request title"); 253 | } 254 | 255 | if (this.enableAssigneesCheckBox.isSelected() && (this.assigneeListModel == null || this.assigneeListModel.isEmpty())) { 256 | validationErrors.add("Please set at least one assignee"); 257 | } 258 | return validationErrors; 259 | } 260 | 261 | private void warnInvalidServer(Throwable throwable) { 262 | String errorMessage = getInvalidServerErrorMessage(throwable); 263 | JBPopupFactory.getInstance() 264 | .createHtmlTextBalloonBuilder(errorMessage, MessageType.ERROR, null) 265 | .setFadeoutTime(7500) 266 | .createBalloon() 267 | .show(RelativePoint.getNorthWestOf(this.validateServerButton), 268 | Balloon.Position.atRight); 269 | } 270 | 271 | private String getInvalidServerErrorMessage(Throwable throwable) { 272 | String defaultErrorMessage = "GitLab is not available. Please check URL or access token."; 273 | StringBuilder additionalErrorMessage = new StringBuilder("\n"); 274 | Throwable cause = throwable; 275 | if (throwable instanceof CompletionException) { 276 | cause = throwable.getCause(); 277 | } 278 | if (cause instanceof SSLPeerUnverifiedException) { 279 | defaultErrorMessage = ""; 280 | additionalErrorMessage.setLength(0); 281 | additionalErrorMessage.append("SSL/TLS certificate is not valid.\nIf you are using a self-signed TLS certificate on GitLab, please check the 'Insecure TLS' checkbox"); 282 | } 283 | 284 | if (cause instanceof IllegalGitLabUrlException) { 285 | defaultErrorMessage = ""; 286 | additionalErrorMessage.setLength(0); 287 | additionalErrorMessage.append(cause.getMessage()); 288 | } 289 | if (cause instanceof JsonSyntaxException) { 290 | defaultErrorMessage = ""; 291 | additionalErrorMessage.setLength(0); 292 | additionalErrorMessage.append("This is not a valid GitLab V4 REST API URL\nServer URL must end with /api/v4. Example: http://gitlab.com/api/v4"); 293 | } 294 | if (cause instanceof HttpResponseException) { 295 | HttpResponseException httpResponseException = (HttpResponseException) cause; 296 | additionalErrorMessage 297 | .append("HTTP Status: ").append(httpResponseException.getStatusCode()).append("\n") 298 | .append("HTTP Reply: ").append(httpResponseException.getMessage()); 299 | } 300 | if (cause instanceof GitLabHttpResponseException) { 301 | GitLabHttpResponseException gitLabHttpResponseException = (GitLabHttpResponseException) cause; 302 | GitLabHttpResponseBody responseBody = gitLabHttpResponseException.getResponseBody(); 303 | if (gitLabHttpResponseException.getStatusCode() == 404) { 304 | defaultErrorMessage = ""; 305 | additionalErrorMessage.append("GitLab V4 REST API not found in this URL\n"); 306 | } 307 | if (gitLabHttpResponseException.getStatusCode() == 503) { 308 | defaultErrorMessage = ""; 309 | if (responseBody.containsCaseInsensitive("checking your browser")) { 310 | additionalErrorMessage.append("GitLab V4 REST API not found in this URL\n"); 311 | } 312 | } 313 | additionalErrorMessage 314 | .append("HTTP Status: ").append(gitLabHttpResponseException.getStatusCode()).append("\n") 315 | .append("HTTP Reply: ").append(gitLabHttpResponseException.getMessage()).append("\n") 316 | .append("HTTP Response: ").append(responseBody.asHtml()); 317 | } 318 | String fullErrorMessage = defaultErrorMessage + additionalErrorMessage; 319 | if (fullErrorMessage.startsWith("\n")) { 320 | fullErrorMessage = fullErrorMessage.substring(1); 321 | } 322 | return fullErrorMessage; 323 | } 324 | 325 | //------- 326 | 327 | @Nls(capitalization = Nls.Capitalization.Title) 328 | @Override 329 | public String getDisplayName() { 330 | return "GitLab Quick Merge Request"; 331 | } 332 | 333 | @Nullable 334 | @Override 335 | public JComponent createComponent() { 336 | return this.rootPanel; 337 | } 338 | 339 | @Override 340 | public boolean isModified() { 341 | boolean unmodified = SettingUtils.equals(this.urlTextField, settings.getGitLabUri()) 342 | && !isAccessTokenModified() 343 | && SettingUtils.equals(this.targetBranchTextField, settings.getDefaultTargetBranch()) 344 | && SettingUtils.equals(this.mergeRequestTitleTextField, settings.getDefaultTitle()) 345 | && SettingUtils.equals(this.mergeRequestDescriptionTextArea, settings.getDefaultDescription()) 346 | && SettingUtils.equals(this.labelsTextField, settings.getDefaultLabels()) 347 | && this.enableDefaultAssigneeActionCheckBox.isSelected() == (settings.isEnableMergeRequestToFavoriteAssignee()) 348 | && SettingUtils.hasSameUniqueElements( 349 | this.assigneeListModel.getItems(), 350 | settings.getDefaultAssignees()) 351 | && this.enableAssigneesCheckBox.isSelected() == (settings.isAssigneesEnabled()) 352 | && this.removeSourceBranchCheckbox.isSelected() == (settings.isRemoveSourceBranchOnMerge()) 353 | && this.squashCommitsCheckBox.isSelected() == (settings.isSquashCommits()) 354 | && this.showConfirmationDialogCheckBox.isSelected() == (settings.isShowConfirmationDialog()) 355 | && this.insecureTLSCheckBox.isSelected() == (settings.isInsecureTls()) 356 | ; 357 | 358 | return !unmodified; 359 | } 360 | 361 | private boolean isAccessTokenModified() { 362 | int accessTokenHash = new String(this.accessTokenTextField.getPassword()).hashCode(); 363 | String storedAccessToken = settings.getAccessToken(); 364 | if (storedAccessToken == null) { 365 | storedAccessToken = ""; 366 | } 367 | int storedAccessTokenHash = storedAccessToken.hashCode(); 368 | return accessTokenHash != storedAccessTokenHash; 369 | } 370 | 371 | @Override 372 | public void reset() { 373 | this.settings = this.project.getService(Settings.class); 374 | bindToComponents(settings); 375 | cacheAccessToken(); 376 | } 377 | 378 | private void cacheAccessToken() { 379 | String accessToken = this.settings.getAccessToken(); 380 | if (accessToken == null) { 381 | accessToken = ""; 382 | } 383 | this.accessTokenHashCode = accessToken.hashCode(); 384 | } 385 | 386 | @Override 387 | public void apply() throws ConfigurationException { 388 | List validationErrors = validate(); 389 | if (!validationErrors.isEmpty()) { 390 | throw new ConfigurationException("
  • " + String.join("
  • ", validationErrors)); 391 | } 392 | 393 | settings.setGitLabUri(this.urlTextField.getText()); 394 | settings.setAccessToken(String.valueOf(this.accessTokenTextField.getPassword())); 395 | settings.setDefaultTargetBranch(this.targetBranchTextField.getText()); 396 | settings.setDefaultAssignees(this.assigneeListModel.getItems()); 397 | settings.setDefaultTitle(this.mergeRequestTitleTextField.getText()); 398 | settings.setDefaultDescription(this.mergeRequestDescriptionTextArea.getText()); 399 | settings.setDefaultLabels(this.labelsTextField.getText()); 400 | settings.setEnableMergeRequestToFavoriteAssignee(this.enableDefaultAssigneeActionCheckBox.isSelected()); 401 | settings.setRemoveSourceBranchOnMerge(this.removeSourceBranchCheckbox.isSelected()); 402 | settings.setSquashCommits(this.squashCommitsCheckBox.isSelected()); 403 | settings.setAssigneesEnabled(this.enableAssigneesCheckBox.isSelected()); 404 | settings.setShowConfirmationDialog(this.showConfirmationDialogCheckBox.isSelected()); 405 | settings.setInsecureTls(this.insecureTLSCheckBox.isSelected()); 406 | } 407 | 408 | public static class ConfigurableProvider implements VcsConfigurableProvider { 409 | @Override 410 | public Configurable getConfigurable(Project project) { 411 | return new SettingsUi(project); 412 | } 413 | } 414 | } 415 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | com.github.novotnyr.gitlab-quickmr-idea-plugin 3 | GitLab Quick Merge Request 4 | RELEASE 5 | Róbert Novotný 6 | 7 | 9 |
      10 |
    • Quickly create merge requests with default settings and submit them with a single click
    • 11 |
    • Specify your favourite merge request assignees
    • 12 |
    • Supports GitLab API v4
    • 13 |
    14 | ]]>
    15 | 16 | 18 |
  • Show explicit context menu item when no assignees are set up in preferences
  • 19 | 20 | ]]> 21 | 22 | 23 | 24 | 25 | com.intellij.modules.lang 26 | com.intellij.modules.vcs 27 | Git4Idea 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 42 | 43 | 44 | 45 | 46 | 47 | 51 | 52 | 53 | 54 | 55 | --------------------------------------------------------------------------------