├── .gitignore ├── .idea ├── markdown-navigator │ └── profiles_settings.xml ├── vcs.xml ├── modules.xml ├── misc.xml └── markdown-navigator.xml ├── resources └── META-INF │ ├── coding-tracker.xml │ └── plugin.xml ├── dev.md ├── Coding-Plugin-for-JetBrains.iml ├── src ├── org │ └── coding │ │ └── git │ │ ├── exceptions │ │ ├── CodingNetTwoFactorAuthenticationException.java │ │ ├── CodingNetJsonException.java │ │ ├── CodingNetAuthenticationException.java │ │ ├── CodingNetOperationCanceledException.java │ │ ├── CodingNetStatusCodeException.java │ │ └── CodingNetConfusingException.java │ │ ├── api │ │ ├── ICodingNetDataConstructor.java │ │ ├── CodingNetBranch.java │ │ ├── CodingNetOrg.java │ │ ├── CodingNetChangeIssueStateRequest.java │ │ ├── CodingNetAuthorizationUpdateRequest.java │ │ ├── CodingNetIssuesSearchResult.java │ │ ├── CodingNetCommitSha.java │ │ ├── CodingNetRepoRequest.java │ │ ├── CodingNetPullRequestRequest.java │ │ ├── CodingNetAuthorizationCreateRequest.java │ │ ├── CodingNetBranchRaw.java │ │ ├── CodingNetOrgRaw.java │ │ ├── CodingNetUser.java │ │ ├── CodingNetAuthorization.java │ │ ├── CodingNetAuthorizationRaw.java │ │ ├── CodingNetIssuesSearchResultRaw.java │ │ ├── CodingNetFileRaw.java │ │ ├── CodingNetGistRequest.java │ │ ├── CodingNetIssueCommentRaw.java │ │ ├── CodingNetRepoDetailed.java │ │ ├── CodingNetCommitCommentRaw.java │ │ ├── CodingNetIssueRaw.java │ │ ├── CodingNetRepoOrg.java │ │ ├── CodingNetIssueComment.java │ │ ├── CodingNetFullPath.java │ │ ├── CodingNetFile.java │ │ ├── CodingNetCommitDetailed.java │ │ ├── CodingNetErrorMessage.java │ │ ├── CodingNetGistRaw.java │ │ ├── CodingNetCommitComment.java │ │ ├── CodingNetPullRequestRaw.java │ │ ├── CodingNetIssue.java │ │ ├── CodingNetUserDetailed.java │ │ ├── CodingNetRepo.java │ │ ├── CodingNetCommit.java │ │ ├── CodingNetUserRaw.java │ │ ├── CodingNetGist.java │ │ ├── CodingNetCommitRaw.java │ │ ├── CodingNetPullRequest.java │ │ └── CodingNetRepoRaw.java │ │ ├── ui │ │ ├── CodingNetBasicLoginDialog.java │ │ ├── CodingNetSettingsConfigurableProvider.java │ │ ├── CodingNetLoginDialog.java │ │ ├── CodingNetLoginPanel.form │ │ ├── CodingNetLoginPanel.java │ │ └── CodingNetSettingsPanel.form │ │ ├── util │ │ ├── CodingNetAuthDataHolder.java │ │ ├── CodingNetUrlUtil.java │ │ ├── CodingNetAuthData.java │ │ ├── CodingNetNotifications.java │ │ └── CodingNetSettings.java │ │ ├── security │ │ └── CodingNetSecurityUtil.java │ │ ├── tasks │ │ ├── CodingNetComment.java │ │ ├── CodingNetRepositoryType.java │ │ └── CodingNetRepositoryEditor.java │ │ ├── check │ │ └── CodingNetGitCloneDialog.java │ │ ├── providers │ │ └── CodingNetCheckoutProvider.java │ │ └── CodingNetOpenAPICodeMsg.java └── icons │ └── CodingNetIcons.java ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | out/ 2 | .DS_Store 3 | *.jar -------------------------------------------------------------------------------- /.idea/markdown-navigator/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /resources/META-INF/coding-tracker.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /dev.md: -------------------------------------------------------------------------------- 1 | ## How to dev 2 | 3 | See https://www.jetbrains.com/help/idea/plugin-development-guidelines.html 4 | 5 | ### import jar 6 | 7 | add jars under `plugins/tasks` and `plugins/git4idea` in `Platform Settings -> SDKs -> Intelli xxx -> Classpath` 8 | 9 | ### dev 10 | click plugin run on right-top 11 | 12 | ### build 13 | right-click on project and run `Prepare Plugin Module for xxxxxx` 14 | 15 | ## Acknowledgement 16 | 17 | https://github.com/JetBrains/intellij-community/tree/master/plugins/github -------------------------------------------------------------------------------- /Coding-Plugin-for-JetBrains.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/org/coding/git/exceptions/CodingNetTwoFactorAuthenticationException.java: -------------------------------------------------------------------------------- 1 | package org.coding.git.exceptions; 2 | 3 | /** 4 | * 两步验证异常定义 5 | * @author robin 6 | */ 7 | public class CodingNetTwoFactorAuthenticationException extends CodingNetAuthenticationException { 8 | public CodingNetTwoFactorAuthenticationException() { 9 | super(); 10 | } 11 | 12 | public CodingNetTwoFactorAuthenticationException(String message) { 13 | super(message); 14 | } 15 | 16 | public CodingNetTwoFactorAuthenticationException(String message, Throwable cause) { 17 | super(message, cause); 18 | } 19 | 20 | public CodingNetTwoFactorAuthenticationException(Throwable cause) { 21 | super(cause); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/org/coding/git/api/ICodingNetDataConstructor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | 20 | /** 21 | * @author robin 22 | */ 23 | interface ICodingNetDataConstructor { 24 | @NotNull 25 | T create(@NotNull Class resultClass) throws IllegalArgumentException, NullPointerException, ClassCastException; 26 | } 27 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetBranch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | 20 | 21 | public class CodingNetBranch { 22 | @NotNull private final String name; 23 | 24 | public CodingNetBranch(@NotNull String name) { 25 | this.name = name; 26 | } 27 | 28 | @NotNull 29 | public String getName() { 30 | return name; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetOrg.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | 20 | 21 | public class CodingNetOrg { 22 | @NotNull private final String myLogin; 23 | 24 | public CodingNetOrg(@NotNull String login) { 25 | myLogin = login; 26 | } 27 | 28 | @NotNull 29 | public String getLogin() { 30 | return myLogin; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/icons/CodingNetIcons.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package icons; 17 | 18 | import com.intellij.openapi.util.IconLoader; 19 | 20 | import javax.swing.*; 21 | 22 | public class CodingNetIcons { 23 | private static Icon load(String path) { 24 | return IconLoader.getIcon(path, CodingNetIcons.class); 25 | } 26 | 27 | public static final Icon Github_icon = load("/org/jetbrains/plugins/github/github_icon.png"); // 16x16 28 | } 29 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetChangeIssueStateRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | 20 | @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) 21 | public class CodingNetChangeIssueStateRequest { 22 | @NotNull private final String state; 23 | 24 | public CodingNetChangeIssueStateRequest(@NotNull String state) { 25 | this.state = state; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetAuthorizationUpdateRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | 20 | import java.util.List; 21 | 22 | @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) 23 | class CodingNetAuthorizationUpdateRequest { 24 | @NotNull private final List addScopes; 25 | 26 | public CodingNetAuthorizationUpdateRequest(@NotNull List newScopes) { 27 | this.addScopes = newScopes; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/org/coding/git/exceptions/CodingNetJsonException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.exceptions; 17 | 18 | public class CodingNetJsonException extends CodingNetConfusingException { 19 | public CodingNetJsonException() { 20 | super(); 21 | } 22 | 23 | public CodingNetJsonException(String message) { 24 | super(message); 25 | } 26 | 27 | public CodingNetJsonException(String message, Throwable cause) { 28 | super(message, cause); 29 | } 30 | 31 | public CodingNetJsonException(Throwable cause) { 32 | super(cause); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetIssuesSearchResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | 20 | import java.util.List; 21 | 22 | 23 | @SuppressWarnings("UnusedDeclaration") 24 | public class CodingNetIssuesSearchResult { 25 | @NotNull private final List issues; 26 | 27 | public CodingNetIssuesSearchResult(@NotNull List issues) { 28 | this.issues = issues; 29 | } 30 | 31 | @NotNull 32 | public List getIssues() { 33 | return issues; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetCommitSha.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | 20 | 21 | @SuppressWarnings("UnusedDeclaration") 22 | public class CodingNetCommitSha { 23 | @NotNull private final String myUrl; 24 | @NotNull private final String mySha; 25 | 26 | public CodingNetCommitSha(@NotNull String url, @NotNull String sha) { 27 | myUrl = url; 28 | mySha = sha; 29 | } 30 | 31 | @NotNull 32 | public String getUrl() { 33 | return myUrl; 34 | } 35 | 36 | @NotNull 37 | public String getSha() { 38 | return mySha; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/org/coding/git/ui/CodingNetBasicLoginDialog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.ui; 17 | 18 | import com.intellij.openapi.project.Project; 19 | import org.jetbrains.annotations.NotNull; 20 | import org.coding.git.util.CodingNetAuthData; 21 | 22 | 23 | /** 24 | * @author robin 25 | */ 26 | public class CodingNetBasicLoginDialog extends CodingNetLoginDialog { 27 | 28 | public CodingNetBasicLoginDialog(@NotNull Project project, @NotNull CodingNetAuthData oldAuthData, @NotNull String host) { 29 | super(project, oldAuthData); 30 | myCodingNetLoginPanel.lockAuthType(CodingNetAuthData.AuthType.BASIC); 31 | myCodingNetLoginPanel.lockHost(host); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetRepoRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import com.google.gson.annotations.SerializedName; 19 | import org.jetbrains.annotations.NotNull; 20 | 21 | 22 | @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) 23 | class CodingNetRepoRequest { 24 | @NotNull private final String name; 25 | @NotNull private final String description; 26 | 27 | @SerializedName("private") private final boolean isPrivate; 28 | 29 | CodingNetRepoRequest(@NotNull String name, @NotNull String description, boolean aPrivate) { 30 | this.name = name; 31 | this.description = description; 32 | isPrivate = aPrivate; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/org/coding/git/exceptions/CodingNetAuthenticationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.exceptions; 17 | 18 | import java.io.IOException; 19 | 20 | /** 21 | *@author robin 22 | */ 23 | public class CodingNetAuthenticationException extends IOException { 24 | public CodingNetAuthenticationException() { 25 | super(); 26 | } 27 | 28 | public CodingNetAuthenticationException(String message) { 29 | super(message); 30 | } 31 | 32 | public CodingNetAuthenticationException(String message, Throwable cause) { 33 | super(message, cause); 34 | } 35 | 36 | public CodingNetAuthenticationException(Throwable cause) { 37 | super(cause); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/org/coding/git/exceptions/CodingNetOperationCanceledException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.exceptions; 17 | 18 | import java.io.IOException; 19 | 20 | 21 | /** 22 | * @author robin 23 | */ 24 | public class CodingNetOperationCanceledException extends IOException { 25 | public CodingNetOperationCanceledException() { 26 | super(); 27 | } 28 | 29 | public CodingNetOperationCanceledException(String message) { 30 | super(message); 31 | } 32 | 33 | public CodingNetOperationCanceledException(String message, Throwable cause) { 34 | super(message, cause); 35 | } 36 | 37 | public CodingNetOperationCanceledException(Throwable cause) { 38 | super(cause); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetPullRequestRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | 20 | 21 | @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) 22 | class CodingNetPullRequestRequest { 23 | @NotNull private final String title; 24 | @NotNull private final String body; 25 | @NotNull private final String head; // branch with changes 26 | @NotNull private final String base; // branch requested to 27 | 28 | public CodingNetPullRequestRequest(@NotNull String title, @NotNull String description, @NotNull String head, @NotNull String base) { 29 | this.title = title; 30 | this.body = description; 31 | this.head = head; 32 | this.base = base; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetAuthorizationCreateRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | import org.jetbrains.annotations.Nullable; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | *@author robin 25 | */ 26 | @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) 27 | class CodingNetAuthorizationCreateRequest { 28 | @NotNull private final List scopes; 29 | 30 | @Nullable private final String note; 31 | @Nullable private final String noteUrl; 32 | 33 | public CodingNetAuthorizationCreateRequest(@NotNull List scopes, @Nullable String note, @Nullable String noteUrl) { 34 | this.scopes = scopes; 35 | this.note = note; 36 | this.noteUrl = noteUrl; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetBranchRaw.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | import org.jetbrains.annotations.Nullable; 20 | 21 | @SuppressWarnings("UnusedDeclaration") 22 | class CodingNetBranchRaw implements ICodingNetDataConstructor { 23 | @Nullable public String name; 24 | 25 | @SuppressWarnings("ConstantConditions") 26 | public CodingNetBranch createBranch() { 27 | return new CodingNetBranch(name); 28 | } 29 | 30 | @SuppressWarnings("unchecked") 31 | @NotNull 32 | @Override 33 | public T create(@NotNull Class resultClass) { 34 | if (resultClass == CodingNetBranch.class) { 35 | return (T)createBranch(); 36 | } 37 | 38 | throw new ClassCastException(this.getClass().getName() + ": bad class type: " + resultClass.getName()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/org/coding/git/exceptions/CodingNetStatusCodeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.exceptions; 17 | 18 | import org.coding.git.api.CodingNetErrorMessage; 19 | import org.jetbrains.annotations.Nullable; 20 | 21 | 22 | public class CodingNetStatusCodeException extends CodingNetConfusingException { 23 | private final int myStatusCode; 24 | private final CodingNetErrorMessage myError; 25 | 26 | public CodingNetStatusCodeException(String message, int statusCode) { 27 | this(message, null, statusCode); 28 | } 29 | 30 | public CodingNetStatusCodeException(String message, CodingNetErrorMessage error, int statusCode) { 31 | super(message); 32 | myStatusCode = statusCode; 33 | myError = error; 34 | } 35 | 36 | public int getStatusCode() { 37 | return myStatusCode; 38 | } 39 | 40 | @Nullable 41 | public CodingNetErrorMessage getError() { 42 | return myError; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetOrgRaw.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | import org.jetbrains.annotations.Nullable; 20 | 21 | 22 | @SuppressWarnings("UnusedDeclaration") 23 | class CodingNetOrgRaw implements ICodingNetDataConstructor { 24 | @Nullable public String login; 25 | @Nullable public Long id; 26 | @Nullable public String url; 27 | 28 | @SuppressWarnings("ConstantConditions") 29 | @NotNull 30 | public CodingNetOrg createGithubOrg() { 31 | return new CodingNetOrg(login); 32 | } 33 | 34 | @SuppressWarnings("unchecked") 35 | @NotNull 36 | @Override 37 | public T create(@NotNull Class resultClass) { 38 | if (resultClass == CodingNetOrg.class) { 39 | return (T)createGithubOrg(); 40 | } 41 | 42 | throw new ClassCastException(this.getClass().getName() + ": bad class type: " + resultClass.getName()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetUser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | import org.jetbrains.annotations.Nullable; 20 | 21 | 22 | /** 23 | * @author robin 24 | */ 25 | public class CodingNetUser { 26 | @NotNull 27 | private String myLogin; 28 | 29 | private String myHtmlUrl; 30 | 31 | private String myAvatarUrl; 32 | 33 | public CodingNetUser() { 34 | 35 | } 36 | 37 | 38 | public CodingNetUser(@NotNull String login, @NotNull String htmlUrl, @Nullable String avatarUrl) { 39 | myLogin = login; 40 | myHtmlUrl = htmlUrl; 41 | myAvatarUrl = avatarUrl; 42 | } 43 | 44 | @NotNull 45 | public String getLogin() { 46 | return myLogin; 47 | } 48 | 49 | @NotNull 50 | public String getHtmlUrl() { 51 | return myHtmlUrl; 52 | } 53 | 54 | @Nullable 55 | public String getAvatarUrl() { 56 | return myAvatarUrl; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetAuthorization.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | import org.jetbrains.annotations.Nullable; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * @author robin 25 | */ 26 | public class CodingNetAuthorization { 27 | private final long myId; 28 | @Nullable private final String myNote; 29 | @NotNull private final String myToken; 30 | @NotNull private final List myScopes; 31 | 32 | public CodingNetAuthorization(long id, @NotNull String token, @NotNull List scopes, @Nullable String note) { 33 | myId = id; 34 | myToken = token; 35 | myScopes = scopes; 36 | myNote = note; 37 | } 38 | 39 | @NotNull 40 | public String getToken() { 41 | return myToken; 42 | } 43 | 44 | @NotNull 45 | public List getScopes() { 46 | return myScopes; 47 | } 48 | 49 | @Nullable 50 | public String getNote() { 51 | return myNote; 52 | } 53 | 54 | public long getId() { 55 | return myId; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/org/coding/git/exceptions/CodingNetConfusingException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.exceptions; 17 | 18 | import org.jetbrains.annotations.Nullable; 19 | 20 | import java.io.IOException; 21 | 22 | 23 | /** 24 | * @author robin 25 | */ 26 | public class CodingNetConfusingException extends IOException { 27 | private String myDetails; 28 | 29 | public CodingNetConfusingException() { 30 | } 31 | 32 | public CodingNetConfusingException(String message) { 33 | super(message); 34 | } 35 | 36 | public CodingNetConfusingException(String message, Throwable cause) { 37 | super(message, cause); 38 | } 39 | 40 | public CodingNetConfusingException(Throwable cause) { 41 | super(cause); 42 | } 43 | 44 | public void setDetails(@Nullable String details) { 45 | myDetails = details; 46 | } 47 | 48 | @Override 49 | public String getMessage() { 50 | if (myDetails == null) { 51 | return super.getMessage(); 52 | } 53 | else { 54 | return myDetails + "\n\n" + super.getMessage(); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetAuthorizationRaw.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | import org.jetbrains.annotations.Nullable; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * @author robin 25 | */ 26 | @SuppressWarnings("UnusedDeclaration") 27 | class CodingNetAuthorizationRaw implements ICodingNetDataConstructor { 28 | @Nullable public Long id; 29 | @Nullable public String url; 30 | @Nullable public String token; 31 | @Nullable public String note; 32 | @Nullable public String noteUrl; 33 | @Nullable public List scopes; 34 | 35 | public CodingNetAuthorization createAuthorization() { 36 | return new CodingNetAuthorization(id, token, scopes, note); 37 | } 38 | 39 | @SuppressWarnings("unchecked") 40 | @NotNull 41 | @Override 42 | public T create(@NotNull Class resultClass) { 43 | if (resultClass == CodingNetAuthorization.class) { 44 | return (T)createAuthorization(); 45 | } 46 | 47 | throw new ClassCastException(this.getClass().getName() + ": bad class type: " + resultClass.getName()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/org/coding/git/util/CodingNetAuthDataHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.util; 17 | 18 | import com.intellij.openapi.util.ThrowableComputable; 19 | import org.jetbrains.annotations.NotNull; 20 | 21 | 22 | /** 23 | * 24 | * 认证数据信息设置管理 25 | * 26 | * @author robin 27 | * 28 | */ 29 | public class CodingNetAuthDataHolder { 30 | @NotNull private CodingNetAuthData myAuthData; 31 | 32 | public CodingNetAuthDataHolder(@NotNull CodingNetAuthData auth) { 33 | myAuthData = auth; 34 | } 35 | 36 | @NotNull 37 | public synchronized CodingNetAuthData getAuthData() { 38 | return myAuthData; 39 | } 40 | 41 | public synchronized void runTransaction(@NotNull CodingNetAuthData expected, 42 | @NotNull ThrowableComputable task) throws T { 43 | if (expected != myAuthData) { 44 | return; 45 | } 46 | 47 | myAuthData = task.compute(); 48 | } 49 | 50 | public static CodingNetAuthDataHolder createFromSettings() { 51 | return new CodingNetAuthDataHolder(CodingNetSettings.getInstance().getAuthData()); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/org/coding/git/security/CodingNetSecurityUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.security; 17 | 18 | import java.security.MessageDigest; 19 | import java.security.NoSuchAlgorithmException; 20 | 21 | /** 22 | * Created by robin on 16/8/8. 23 | */ 24 | public class CodingNetSecurityUtil { 25 | 26 | public static String getUserPasswordOfSHA1(String passWord){ 27 | try { 28 | MessageDigest digest = MessageDigest 29 | .getInstance("SHA-1"); 30 | digest.update(passWord.getBytes()); 31 | byte messageDigest[] = digest.digest(); 32 | StringBuffer hexString = new StringBuffer(); 33 | for (int i = 0; i < messageDigest.length; i++) { 34 | String shaHex = Integer.toHexString(messageDigest[i] & 0xFF); 35 | if (shaHex.length() < 2) { 36 | hexString.append(0); 37 | } 38 | hexString.append(shaHex); 39 | } 40 | return hexString.toString(); 41 | 42 | } catch (NoSuchAlgorithmException e) { 43 | e.printStackTrace(); 44 | } 45 | return ""; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetIssuesSearchResultRaw.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | import org.jetbrains.annotations.Nullable; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | 25 | @SuppressWarnings({"UnusedDeclaration", "ConstantConditions"}) 26 | class CodingNetIssuesSearchResultRaw implements ICodingNetDataConstructor { 27 | @Nullable public List items; 28 | 29 | @NotNull 30 | CodingNetIssuesSearchResult createIssueSearchResult() { 31 | List issues = new ArrayList(); 32 | for (CodingNetIssueRaw raw : items) { 33 | issues.add(raw.createIssue()); 34 | } 35 | return new CodingNetIssuesSearchResult(issues); 36 | } 37 | 38 | 39 | @SuppressWarnings("unchecked") 40 | @NotNull 41 | @Override 42 | public T create(@NotNull Class resultClass) { 43 | if (resultClass == CodingNetIssuesSearchResult.class) { 44 | return (T)createIssueSearchResult(); 45 | } 46 | 47 | throw new ClassCastException(this.getClass().getName() + ": bad class type: " + resultClass.getName()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetFileRaw.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | import org.jetbrains.annotations.Nullable; 20 | 21 | @SuppressWarnings("UnusedDeclaration") 22 | class CodingNetFileRaw implements ICodingNetDataConstructor { 23 | @Nullable public String filename; 24 | 25 | @Nullable public Integer additions; 26 | @Nullable public Integer deletions; 27 | @Nullable public Integer changes; 28 | @Nullable public String status; 29 | @Nullable public String rawUrl; 30 | @Nullable public String blobUrl; 31 | @Nullable public String patch; 32 | 33 | @SuppressWarnings("ConstantConditions") 34 | @NotNull 35 | public CodingNetFile createFile() { 36 | return new CodingNetFile(filename, additions, deletions, changes, status, rawUrl, patch); 37 | } 38 | 39 | @SuppressWarnings("unchecked") 40 | @NotNull 41 | @Override 42 | public T create(@NotNull Class resultClass) { 43 | if (resultClass == CodingNetFile.class) { 44 | return (T)createFile(); 45 | } 46 | 47 | throw new ClassCastException(this.getClass().getName() + ": bad class type: " + resultClass.getName()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetGistRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import com.google.gson.annotations.SerializedName; 19 | import com.intellij.util.containers.HashMap; 20 | import org.jetbrains.annotations.NotNull; 21 | 22 | import java.util.List; 23 | import java.util.Map; 24 | 25 | @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration", "MismatchedQueryAndUpdateOfCollection"}) 26 | class CodingNetGistRequest { 27 | @NotNull private final String description; 28 | @NotNull private final Map files; 29 | 30 | @SerializedName("public") 31 | private final boolean isPublic; 32 | 33 | public static class GistFile { 34 | @NotNull private final String content; 35 | 36 | public GistFile(@NotNull String content) { 37 | this.content = content; 38 | } 39 | } 40 | 41 | public CodingNetGistRequest(@NotNull List files, @NotNull String description, boolean isPublic) { 42 | this.description = description; 43 | this.isPublic = isPublic; 44 | 45 | this.files = new HashMap(); 46 | for (CodingNetGist.FileContent file : files) { 47 | this.files.put(file.getFileName(), new GistFile(file.getContent())); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Banner](http://7xii9k.com1.z0.glb.clouddn.com/2016-08-24-IDEACodingPlugin.png) 2 | 3 | ## Coding.net Plugin for JetBrains 4 | 插件地址:https://plugins.jetbrains.com/plugin/8565 5 | 6 | Coding.net Plugin 适用于 JetBrains 全系列开发工具。通过 Coding.net Plugin,您可以在 IDE 中直接 Clone Coding 账户中的 Git 仓库! 7 | 8 | ### 安装 Coding.net Plugin 9 | 1.打开 IDE 的 Plugins 面板,下面以 IDEA 为例。 10 | 11 | ![Welcome](http://7xii9k.com1.z0.glb.clouddn.com/2016-08-24-11:42:10.jpg) 12 | 13 | 2.通过「Browse repositories...」直接搜索安装插件,如果已经下载了插件文件,可以通过「Install plugin from disk...」安装。 14 | 15 | ![Plugins](http://7xii9k.com1.z0.glb.clouddn.com/2016-08-24-11:49:22.jpg) 16 | 17 | 3.在 Browse Repositories 面板中搜索「coding.net」安装插件,然后按照提示重启 IDEA 完成安装。 18 | 19 | ![Browse](http://7xii9k.com1.z0.glb.clouddn.com/2016-08-24-11:48:53.jpg) 20 | 21 | ### 在 IDE 中 Clone Coding 仓库 22 | 1.安装完 Coding.net 插件后就可以在「Check out from Version Control」中看到 Coding.net。 23 | 24 | ![VCS](http://7xii9k.com1.z0.glb.clouddn.com/2016-08-24-11:17:25.jpg) 25 | 26 | 2.Host 中填入「coding.net」,支持使用邮箱、用户名和手机号登录。 27 | 28 | ![Login](http://7xii9k.com1.z0.glb.clouddn.com/2016-08-24-11:22:58.jpg) 29 | 30 | 3.如果账号开启了两部验证的话需填入两步验证码进行验证。没开启两步验证的用户不会出现这个弹窗。 31 | 32 | ![TwoFactor Authentication](http://7xii9k.com1.z0.glb.clouddn.com/2016-08-24-11:21:32.jpg) 33 | 34 | 4.成功登录后就可以开始 Clone Coding 账号中的 Git 仓库了,私有项目与公开项目都会出现在仓库列表中。 35 | 36 | ![Repo List](http://7xii9k.com1.z0.glb.clouddn.com/2016-08-24-11:20:57.jpg) 37 | 38 | ### 其它 39 | 您可以在 IDEA 的配置面板中修改 Coding.net 相关配置。 40 | 41 | ![Preferences](http://7xii9k.com1.z0.glb.clouddn.com/2016-08-24-12:54:37.jpg) 42 | 43 | 现在,开始使用 [Coding.net Plugin for JetBrains](https://plugins.jetbrains.com/plugin/8565) 并进行评价吧。 44 | Coding.net Plugin 兼容到 Build 162 的 IDE,请使用最新 IDE 安装体验。 45 | 46 | **疑问与建议请在 https://coding.net/feedback 反馈,感谢使用。** 47 | 48 | ### License 49 | Coding Plugin is available under the Apache v2 license. See the LICENSE file for more info. -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetIssueCommentRaw.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | import org.jetbrains.annotations.Nullable; 20 | 21 | import java.util.Date; 22 | 23 | 24 | @SuppressWarnings("UnusedDeclaration") 25 | class CodingNetIssueCommentRaw implements ICodingNetDataConstructor { 26 | @Nullable public Long id; 27 | 28 | @Nullable public String url; 29 | @Nullable public String htmlUrl; 30 | @Nullable public String body; 31 | @Nullable public String bodyHtml; 32 | 33 | @Nullable public Date createdAt; 34 | @Nullable public Date updatedAt; 35 | 36 | @Nullable public CodingNetUserRaw user; 37 | 38 | @SuppressWarnings("ConstantConditions") 39 | @NotNull 40 | public CodingNetIssueComment createIssueComment() { 41 | return new CodingNetIssueComment(id, htmlUrl, bodyHtml, createdAt, updatedAt, user.createUser()); 42 | } 43 | 44 | @SuppressWarnings("unchecked") 45 | @NotNull 46 | @Override 47 | public T create(@NotNull Class resultClass) { 48 | if (resultClass == CodingNetIssueComment.class) { 49 | return (T)createIssueComment(); 50 | } 51 | 52 | throw new ClassCastException(this.getClass().getName() + ": bad class type: " + resultClass.getName()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetRepoDetailed.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | import org.jetbrains.annotations.Nullable; 20 | 21 | 22 | public class CodingNetRepoDetailed extends CodingNetRepo { 23 | @Nullable private final CodingNetRepo myParent; 24 | @Nullable private final CodingNetRepo mySource; 25 | 26 | public CodingNetRepoDetailed(@NotNull String name, 27 | @Nullable String description, 28 | boolean isPrivate, 29 | boolean isFork, 30 | @NotNull String htmlUrl, 31 | @NotNull String cloneUrl, 32 | @Nullable String defaultBranch, 33 | @NotNull CodingNetUser owner, 34 | @Nullable CodingNetRepo parent, 35 | @Nullable CodingNetRepo source) { 36 | super(name, description, isPrivate, isFork, htmlUrl, cloneUrl, defaultBranch, owner); 37 | myParent = parent; 38 | mySource = source; 39 | } 40 | 41 | @Nullable 42 | public CodingNetRepo getParent() { 43 | return myParent; 44 | } 45 | 46 | @Nullable 47 | public CodingNetRepo getSource() { 48 | return mySource; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetCommitCommentRaw.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | import org.jetbrains.annotations.Nullable; 20 | 21 | import java.util.Date; 22 | 23 | 24 | class CodingNetCommitCommentRaw implements ICodingNetDataConstructor { 25 | @Nullable public String htmlUrl; 26 | @Nullable public String url; 27 | 28 | @Nullable public Long id; 29 | @Nullable public String commitId; 30 | @Nullable public String path; 31 | @Nullable public Long position; 32 | @Nullable public Long line; 33 | @Nullable public String body; 34 | @Nullable public String bodyHtml; 35 | 36 | @Nullable public CodingNetUserRaw user; 37 | 38 | @Nullable public Date createdAt; 39 | @Nullable public Date updatedAt; 40 | 41 | @SuppressWarnings("ConstantConditions") 42 | @NotNull 43 | public CodingNetCommitComment createCommitComment() { 44 | return new CodingNetCommitComment(htmlUrl, id, commitId, path, position, bodyHtml, user.createUser(), createdAt, updatedAt); 45 | } 46 | 47 | @SuppressWarnings("unchecked") 48 | @NotNull 49 | @Override 50 | public T create(@NotNull Class resultClass) { 51 | if (resultClass == CodingNetCommitComment.class) { 52 | return (T)createCommitComment(); 53 | } 54 | 55 | throw new ClassCastException(this.getClass().getName() + ": bad class type: " + resultClass.getName()); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetIssueRaw.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | import org.jetbrains.annotations.Nullable; 20 | 21 | import java.util.Date; 22 | 23 | 24 | @SuppressWarnings("UnusedDeclaration") 25 | class CodingNetIssueRaw implements ICodingNetDataConstructor { 26 | @Nullable public String url; 27 | @Nullable public String htmlUrl; 28 | @Nullable public Long number; 29 | @Nullable public String state; 30 | @Nullable public String title; 31 | @Nullable public String body; 32 | 33 | @Nullable public CodingNetUserRaw user; 34 | @Nullable public CodingNetUserRaw assignee; 35 | 36 | @Nullable public Date closedAt; 37 | @Nullable public Date createdAt; 38 | @Nullable public Date updatedAt; 39 | 40 | @SuppressWarnings("ConstantConditions") 41 | @NotNull 42 | public CodingNetIssue createIssue() { 43 | CodingNetUser assignee = this.assignee == null ? null : this.assignee.createUser(); 44 | return new CodingNetIssue(htmlUrl, number, state, title, body, user.createUser(), assignee, closedAt, createdAt, updatedAt); 45 | } 46 | 47 | @SuppressWarnings("unchecked") 48 | @NotNull 49 | @Override 50 | public T create(@NotNull Class resultClass) { 51 | if (resultClass == CodingNetIssue.class) { 52 | return (T)createIssue(); 53 | } 54 | 55 | throw new ClassCastException(this.getClass().getName() + ": bad class type: " + resultClass.getName()); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetRepoOrg.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | import org.jetbrains.annotations.Nullable; 20 | 21 | @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) 22 | public class CodingNetRepoOrg extends CodingNetRepo { 23 | @NotNull private final Permissions myPermissions; 24 | 25 | public static class Permissions { 26 | private final boolean myAdmin; 27 | private final boolean myPull; 28 | private final boolean myPush; 29 | 30 | public Permissions(boolean admin, boolean pull, boolean push) { 31 | myAdmin = admin; 32 | myPull = pull; 33 | myPush = push; 34 | } 35 | 36 | public boolean isAdmin() { 37 | return myAdmin; 38 | } 39 | 40 | public boolean isPull() { 41 | return myPull; 42 | } 43 | 44 | public boolean isPush() { 45 | return myPush; 46 | } 47 | } 48 | 49 | public CodingNetRepoOrg(@NotNull String name, 50 | @Nullable String description, 51 | boolean isPrivate, 52 | boolean isFork, 53 | @NotNull String htmlUrl, 54 | @NotNull String cloneUrl, 55 | @Nullable String defaultBranch, 56 | @NotNull CodingNetUser owner, 57 | @NotNull Permissions permissions) { 58 | super(name, description, isPrivate, isFork, htmlUrl, cloneUrl, defaultBranch, owner); 59 | myPermissions = permissions; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetIssueComment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | 20 | import java.util.Date; 21 | 22 | /** 23 | * @author Aleksey Pivovarov 24 | */ 25 | public class CodingNetIssueComment { 26 | private final long myId; 27 | 28 | @NotNull private final String myHtmlUrl; 29 | @NotNull private final String myBodyHtml; 30 | 31 | @NotNull private final Date myCreatedAt; 32 | @NotNull private final Date myUpdatedAt; 33 | 34 | @NotNull private final CodingNetUser myUser; 35 | 36 | public CodingNetIssueComment(long id, 37 | @NotNull String htmlUrl, 38 | @NotNull String bodyHtml, 39 | @NotNull Date createdAt, 40 | @NotNull Date updatedAt, 41 | @NotNull CodingNetUser user) { 42 | myId = id; 43 | myHtmlUrl = htmlUrl; 44 | myBodyHtml = bodyHtml; 45 | myCreatedAt = createdAt; 46 | myUpdatedAt = updatedAt; 47 | myUser = user; 48 | } 49 | 50 | public long getId() { 51 | return myId; 52 | } 53 | 54 | @NotNull 55 | public String getHtmlUrl() { 56 | return myHtmlUrl; 57 | } 58 | 59 | @NotNull 60 | public String getBodyHtml() { 61 | return myBodyHtml; 62 | } 63 | 64 | @NotNull 65 | public Date getCreatedAt() { 66 | return myCreatedAt; 67 | } 68 | 69 | @NotNull 70 | public Date getUpdatedAt() { 71 | return myUpdatedAt; 72 | } 73 | 74 | @NotNull 75 | public CodingNetUser getUser() { 76 | return myUser; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetFullPath.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import com.intellij.openapi.util.text.StringUtil; 19 | import org.jetbrains.annotations.NotNull; 20 | import org.jetbrains.annotations.Nullable; 21 | 22 | 23 | public class CodingNetFullPath { 24 | @NotNull private final String myUserName; 25 | @NotNull private final String myRepositoryName; 26 | 27 | public CodingNetFullPath(@NotNull String userName, @NotNull String repositoryName) { 28 | myUserName = userName; 29 | myRepositoryName = repositoryName; 30 | } 31 | 32 | @NotNull 33 | public String getUser() { 34 | return myUserName; 35 | } 36 | 37 | @NotNull 38 | public String getRepository() { 39 | return myRepositoryName; 40 | } 41 | 42 | @NotNull 43 | public String getFullName() { 44 | return myUserName + '/' + myRepositoryName; 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return "'" + getFullName() + "'"; 50 | } 51 | 52 | @Override 53 | public boolean equals(@Nullable Object o) { 54 | if (this == o) return true; 55 | if (o == null || getClass() != o.getClass()) return false; 56 | 57 | CodingNetFullPath that = (CodingNetFullPath)o; 58 | 59 | if (!StringUtil.equalsIgnoreCase(myRepositoryName, that.myRepositoryName)) return false; 60 | if (!StringUtil.equalsIgnoreCase(myUserName, that.myUserName)) return false; 61 | 62 | return true; 63 | } 64 | 65 | @Override 66 | public int hashCode() { 67 | int result = myUserName.hashCode(); 68 | result = 31 * result + myRepositoryName.hashCode(); 69 | return result; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | 20 | 21 | @SuppressWarnings("UnusedDeclaration") 22 | public class CodingNetFile { 23 | @NotNull private final String myFilename; 24 | 25 | private final int myAdditions; 26 | private final int myDeletions; 27 | private final int myChanges; 28 | @NotNull private final String myStatus; 29 | 30 | @NotNull private final String myRawUrl; 31 | @NotNull private final String myPatch; 32 | 33 | public CodingNetFile(@NotNull String filename, int additions, 34 | int deletions, 35 | int changes, 36 | @NotNull String status, 37 | @NotNull String rawUrl, 38 | @NotNull String patch) { 39 | myFilename = filename; 40 | myAdditions = additions; 41 | myDeletions = deletions; 42 | myChanges = changes; 43 | myStatus = status; 44 | myRawUrl = rawUrl; 45 | myPatch = patch; 46 | } 47 | 48 | @NotNull 49 | public String getFilename() { 50 | return myFilename; 51 | } 52 | 53 | public int getAdditions() { 54 | return myAdditions; 55 | } 56 | 57 | public int getDeletions() { 58 | return myDeletions; 59 | } 60 | 61 | public int getChanges() { 62 | return myChanges; 63 | } 64 | 65 | @NotNull 66 | public String getStatus() { 67 | return myStatus; 68 | } 69 | 70 | @NotNull 71 | public String getRawUrl() { 72 | return myRawUrl; 73 | } 74 | 75 | @NotNull 76 | public String getPatch() { 77 | return myPatch; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/org/coding/git/tasks/CodingNetComment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.tasks; 17 | 18 | import com.intellij.tasks.impl.SimpleComment; 19 | import com.intellij.util.text.DateFormatUtil; 20 | import org.jetbrains.annotations.NotNull; 21 | import org.jetbrains.annotations.Nullable; 22 | 23 | import java.util.Date; 24 | 25 | 26 | public class CodingNetComment extends SimpleComment { 27 | @Nullable private final String myAvatarUrl; 28 | @NotNull private final String myUserHtmlUrl; 29 | 30 | public CodingNetComment(@Nullable Date date, 31 | @Nullable String author, 32 | @NotNull String text, 33 | @Nullable String avatarUrl, 34 | @NotNull String userHtmlUrl) { 35 | super(date, author, text); 36 | myAvatarUrl = avatarUrl; 37 | myUserHtmlUrl = userHtmlUrl; 38 | } 39 | 40 | public void appendTo(StringBuilder builder) { 41 | builder.append("
"); 42 | builder.append(""); 43 | builder.append("
"); 44 | if (myAvatarUrl != null) { 45 | builder.append("
"); 46 | } 47 | builder.append("
"); 48 | if (getAuthor() != null) { 49 | builder.append("Author: ").append(getAuthor()).append("
"); 50 | } 51 | if (getDate() != null) { 52 | builder.append("Date: ").append(DateFormatUtil.formatDateTime(getDate())).append("
"); 53 | } 54 | builder.append("
"); 55 | 56 | builder.append(getText()).append("
"); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/org/coding/git/tasks/CodingNetRepositoryType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.tasks; 17 | 18 | import com.intellij.openapi.project.Project; 19 | import com.intellij.tasks.TaskRepository; 20 | import com.intellij.tasks.TaskState; 21 | import com.intellij.tasks.config.TaskRepositoryEditor; 22 | import com.intellij.tasks.impl.BaseRepositoryType; 23 | import com.intellij.util.Consumer; 24 | import icons.CodingNetIcons; 25 | import icons.TasksIcons; 26 | import org.jetbrains.annotations.NotNull; 27 | 28 | import javax.swing.*; 29 | import java.util.EnumSet; 30 | 31 | 32 | /** 33 | * @author robin 34 | * Coding Git仓库 35 | */ 36 | public class CodingNetRepositoryType extends BaseRepositoryType { 37 | 38 | @NotNull 39 | @Override 40 | public String getName() { 41 | return "Coding"; 42 | } 43 | 44 | @NotNull 45 | @Override 46 | public Icon getIcon() { 47 | return CodingNetIcons.Github_icon; 48 | } 49 | 50 | @NotNull 51 | @Override 52 | public TaskRepository createRepository() { 53 | return new CodingNetRepository(this); 54 | } 55 | 56 | @Override 57 | public Class getRepositoryClass() { 58 | return CodingNetRepository.class; 59 | } 60 | 61 | @NotNull 62 | @Override 63 | public TaskRepositoryEditor createEditor(CodingNetRepository repository, 64 | Project project, 65 | Consumer changeListener) { 66 | return new CodingNetRepositoryEditor(project, repository, changeListener); 67 | } 68 | 69 | public EnumSet getPossibleTaskStates() { 70 | return EnumSet.of(TaskState.OPEN, TaskState.RESOLVED); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetCommitDetailed.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | import org.jetbrains.annotations.Nullable; 20 | 21 | import java.util.List; 22 | 23 | 24 | @SuppressWarnings("UnusedDeclaration") 25 | public class CodingNetCommitDetailed extends CodingNetCommit { 26 | @NotNull private final CommitStats myStats; 27 | @NotNull private final List myFiles; 28 | 29 | public static class CommitStats { 30 | private final int myAdditions; 31 | private final int myDeletions; 32 | private final int myTotal; 33 | 34 | public CommitStats(int additions, int deletions, int total) { 35 | myAdditions = additions; 36 | myDeletions = deletions; 37 | myTotal = total; 38 | } 39 | 40 | public int getAdditions() { 41 | return myAdditions; 42 | } 43 | 44 | public int getDeletions() { 45 | return myDeletions; 46 | } 47 | 48 | public int getTotal() { 49 | return myTotal; 50 | } 51 | } 52 | 53 | public CodingNetCommitDetailed(@NotNull String url, 54 | @NotNull String sha, 55 | @Nullable CodingNetUser author, 56 | @Nullable CodingNetUser committer, 57 | @NotNull List parents, 58 | @NotNull GitCommit commit, 59 | @NotNull CommitStats stats, 60 | @NotNull List files) { 61 | super(url, sha, author, committer, parents, commit); 62 | myStats = stats; 63 | myFiles = files; 64 | } 65 | 66 | @NotNull 67 | public CommitStats getStats() { 68 | return myStats; 69 | } 70 | 71 | @NotNull 72 | public List getFiles() { 73 | return myFiles; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetErrorMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | import org.jetbrains.annotations.Nullable; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * @author robin 25 | * 26 | * Based on https://github.com/JetBrains/intellij-community/blob/master/plugins/github/src/org/jetbrains/plugins/github/api/GithubErrorMessage.java 27 | * @author JetBrains s.r.o. 28 | * @author Aleksey Pivovarov 29 | */ 30 | 31 | @SuppressWarnings("UnusedDeclaration") 32 | public class CodingNetErrorMessage { 33 | @Nullable public String message; 34 | @Nullable public List errors; 35 | 36 | public static class Error { 37 | @Nullable public String resource; 38 | @Nullable public String field; 39 | @Nullable public String code; 40 | @Nullable public String message; 41 | } 42 | 43 | @Nullable 44 | public String getMessage() { 45 | if (errors == null) { 46 | return message; 47 | } 48 | else { 49 | StringBuilder s = new StringBuilder(); 50 | s.append(message); 51 | for (Error e : errors) { 52 | s.append(String.format("
[%s; %s]%s: %s", e.resource, e.field, e.code, e.message)); 53 | } 54 | return s.toString(); 55 | } 56 | } 57 | 58 | public boolean containsReasonMessage(@NotNull String reason) { 59 | if (message == null) return false; 60 | return message.contains(reason); 61 | } 62 | 63 | public boolean containsErrorCode(@NotNull String code) { 64 | if (errors == null) return false; 65 | for (Error error : errors) { 66 | if (error.code != null && error.code.contains(code)) return true; 67 | } 68 | return false; 69 | } 70 | 71 | public boolean containsErrorMessage(@NotNull String message) { 72 | if (errors == null) return false; 73 | for (Error error : errors) { 74 | if (error.code != null && error.code.contains(message)) return true; 75 | } 76 | return false; 77 | } 78 | } 79 | 80 | -------------------------------------------------------------------------------- /resources/META-INF/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | net.coding.git 3 | Coding.net 4 | 1.1.0 5 | Coding 6 | 7 | Coding.net. 10 |

11 | ABOUT CODING 12 |

13 | CODING established in February 2014, is one of the most advanced service platforms for software could-developing in China.

14 | Coding.net and CodeMart are the major sub-brands of CODING. The former acts as an on-cloud coordinate stage to provide service and tools for on-cloud software developing. The key service of Coding.net includes code trusteeship, project management, product display and WebIDE.

15 | CodeMart was launched on October 2015. It functioned as an crowdsourcing platform. Different from traditional crowdsourcing platforms, the vision of CodeMart is more than an information provider or task-board manager. It’s not only connecting developers and clients, but also supervising the whole process in order to ensure high efficiency and the safety of their on-cloud cooperation. 16 |

17 | This Plugin is a CodeMart Project. 18 |
19 | Develop by r0b1n_0u 20 | ]]>
21 | 22 | 24 | 25 | 26 | 27 | 28 | 29 | 31 | 32 | com.intellij.modules.lang 33 | Git4Idea 34 | com.intellij.tasks 35 | 36 | 37 | 38 | 39 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 |
-------------------------------------------------------------------------------- /src/org/coding/git/ui/CodingNetSettingsConfigurableProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.ui; 17 | 18 | import com.intellij.openapi.options.Configurable; 19 | import com.intellij.openapi.options.ConfigurationException; 20 | import com.intellij.openapi.options.SearchableConfigurable; 21 | import com.intellij.openapi.project.Project; 22 | import com.intellij.openapi.vcs.VcsConfigurableProvider; 23 | import org.jetbrains.annotations.NotNull; 24 | import org.jetbrains.annotations.Nullable; 25 | 26 | import javax.swing.*; 27 | 28 | 29 | /** 30 | * @author robin 31 | * 32 | * * Based on https://github.com/JetBrains/intellij-community/blob/master/plugins/github/src/org/jetbrains/plugins/github/ui/GithubSettingsConfigurable.java 33 | * @author JetBrains s.r.o. 34 | * @author oleg 35 | */ 36 | public class CodingNetSettingsConfigurableProvider implements SearchableConfigurable, VcsConfigurableProvider { 37 | private CodingNetSettingsPanel mySettingsPane; 38 | 39 | public CodingNetSettingsConfigurableProvider() { 40 | } 41 | 42 | @NotNull 43 | public String getDisplayName() { 44 | return "Coding.net"; 45 | } 46 | 47 | @NotNull 48 | public String getHelpTopic() { 49 | return "settings.codingnet"; 50 | } 51 | 52 | @NotNull 53 | public JComponent createComponent() { 54 | if (mySettingsPane == null) { 55 | mySettingsPane = new CodingNetSettingsPanel(); 56 | } 57 | return mySettingsPane.getPanel(); 58 | } 59 | 60 | public boolean isModified() { 61 | return mySettingsPane != null && mySettingsPane.isModified(); 62 | } 63 | 64 | public void apply() throws ConfigurationException { 65 | if (mySettingsPane != null) { 66 | mySettingsPane.apply(); 67 | } 68 | } 69 | 70 | public void reset() { 71 | if (mySettingsPane != null) { 72 | mySettingsPane.reset(); 73 | } 74 | } 75 | 76 | public void disposeUIResources() { 77 | mySettingsPane = null; 78 | } 79 | 80 | @NotNull 81 | public String getId() { 82 | return getHelpTopic(); 83 | } 84 | 85 | public Runnable enableSearch(String option) { 86 | return null; 87 | } 88 | 89 | @Nullable 90 | @Override 91 | public Configurable getConfigurable(Project project) { 92 | return this; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetGistRaw.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import com.google.gson.annotations.SerializedName; 19 | import org.jetbrains.annotations.NotNull; 20 | import org.jetbrains.annotations.Nullable; 21 | 22 | import java.util.ArrayList; 23 | import java.util.Date; 24 | import java.util.List; 25 | import java.util.Map; 26 | 27 | 28 | @SuppressWarnings("UnusedDeclaration") 29 | class CodingNetGistRaw implements ICodingNetDataConstructor { 30 | @Nullable public String id; 31 | @Nullable public String description; 32 | 33 | @SerializedName("public") 34 | @Nullable public Boolean isPublic; 35 | 36 | @Nullable public String url; 37 | @Nullable public String htmlUrl; 38 | @Nullable public String gitPullUrl; 39 | @Nullable public String gitPushUrl; 40 | 41 | @Nullable public Map files; 42 | 43 | @Nullable public CodingNetUserRaw owner; 44 | 45 | @Nullable public Date createdAt; 46 | 47 | public static class GistFileRaw { 48 | @Nullable public Long size; 49 | @Nullable public String filename; 50 | @Nullable public String content; 51 | 52 | @Nullable public String raw_url; 53 | 54 | @Nullable public String type; 55 | @Nullable public String language; 56 | 57 | @SuppressWarnings("ConstantConditions") 58 | @NotNull 59 | public CodingNetGist.GistFile create() { 60 | return new CodingNetGist.GistFile(filename, content, raw_url); 61 | } 62 | } 63 | 64 | @SuppressWarnings("ConstantConditions") 65 | @NotNull 66 | public CodingNetGist createGist() { 67 | CodingNetUser user = this.owner == null ? null : this.owner.createUser(); 68 | 69 | List files = new ArrayList(); 70 | for (Map.Entry entry : this.files.entrySet()) { 71 | files.add(entry.getValue().create()); 72 | } 73 | 74 | return new CodingNetGist(id, description, isPublic, htmlUrl, files, user); 75 | } 76 | 77 | @SuppressWarnings("unchecked") 78 | @NotNull 79 | @Override 80 | public T create(@NotNull Class resultClass) { 81 | if (resultClass == CodingNetGist.class) { 82 | return (T)createGist(); 83 | } 84 | 85 | throw new ClassCastException(this.getClass().getName() + ": bad class type: " + resultClass.getName()); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetCommitComment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | 20 | import java.util.Date; 21 | 22 | 23 | @SuppressWarnings("UnusedDeclaration") 24 | public class CodingNetCommitComment { 25 | @NotNull private final String myHtmlUrl; 26 | 27 | private final long myId; 28 | @NotNull private final String mySha; 29 | @NotNull private final String myPath; 30 | private final long myPosition; // line number in diff 31 | @NotNull private final String myBodyHtml; 32 | 33 | @NotNull private final CodingNetUser myUser; 34 | 35 | @NotNull private final Date myCreatedAt; 36 | @NotNull private final Date myUpdatedAt; 37 | 38 | public CodingNetCommitComment(@NotNull String htmlUrl, 39 | long id, 40 | @NotNull String sha, 41 | @NotNull String path, 42 | long position, 43 | @NotNull String bodyHtml, 44 | @NotNull CodingNetUser user, 45 | @NotNull Date createdAt, 46 | @NotNull Date updatedAt) { 47 | myHtmlUrl = htmlUrl; 48 | myId = id; 49 | mySha = sha; 50 | myPath = path; 51 | myPosition = position; 52 | myBodyHtml = bodyHtml; 53 | myUser = user; 54 | myCreatedAt = createdAt; 55 | myUpdatedAt = updatedAt; 56 | } 57 | 58 | @NotNull 59 | public String getHtmlUrl() { 60 | return myHtmlUrl; 61 | } 62 | 63 | public long getId() { 64 | return myId; 65 | } 66 | 67 | @NotNull 68 | public String getSha() { 69 | return mySha; 70 | } 71 | 72 | @NotNull 73 | public String getPath() { 74 | return myPath; 75 | } 76 | 77 | public long getPosition() { 78 | return myPosition; 79 | } 80 | 81 | @NotNull 82 | public String getBodyHtml() { 83 | return myBodyHtml; 84 | } 85 | 86 | @NotNull 87 | public CodingNetUser getUser() { 88 | return myUser; 89 | } 90 | 91 | @NotNull 92 | public Date getCreatedAt() { 93 | return myCreatedAt; 94 | } 95 | 96 | @NotNull 97 | public Date getUpdatedAt() { 98 | return myUpdatedAt; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetPullRequestRaw.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | import org.jetbrains.annotations.Nullable; 20 | 21 | import java.util.Date; 22 | 23 | 24 | @SuppressWarnings({"UnusedDeclaration", "ConstantConditions"}) 25 | class CodingNetPullRequestRaw implements ICodingNetDataConstructor { 26 | @Nullable public Long number; 27 | @Nullable public String state; 28 | @Nullable public String title; 29 | @Nullable public String body; 30 | @Nullable public String bodyHtml; 31 | 32 | @Nullable public String url; 33 | @Nullable public String htmlUrl; 34 | @Nullable public String diffUrl; 35 | @Nullable public String patchUrl; 36 | @Nullable public String issueUrl; 37 | 38 | @Nullable public Boolean merged; 39 | @Nullable public Boolean mergeable; 40 | 41 | @Nullable public Integer comments; 42 | @Nullable public Integer commits; 43 | @Nullable public Integer additions; 44 | @Nullable public Integer deletions; 45 | @Nullable public Integer changedFiles; 46 | 47 | @Nullable public Date createdAt; 48 | @Nullable public Date updatedAt; 49 | @Nullable public Date closedAt; 50 | @Nullable public Date mergedAt; 51 | 52 | @Nullable public CodingNetUserRaw user; 53 | 54 | @Nullable public LinkRaw head; 55 | @Nullable public LinkRaw base; 56 | 57 | public static class LinkRaw { 58 | @Nullable public String label; 59 | @Nullable public String ref; 60 | @Nullable public String sha; 61 | 62 | @Nullable public CodingNetRepoRaw repo; 63 | @Nullable public CodingNetUserRaw user; 64 | 65 | @NotNull 66 | public CodingNetPullRequest.Link create() { 67 | return new CodingNetPullRequest.Link(label, ref, sha, repo.createRepo(), user.createUser()); 68 | } 69 | } 70 | 71 | @NotNull 72 | public CodingNetPullRequest createPullRequest() { 73 | return new CodingNetPullRequest(number, state, title, bodyHtml, htmlUrl, diffUrl, patchUrl, issueUrl, createdAt, updatedAt, closedAt, mergedAt, 74 | user.createUser(), head.create(), base.create()); 75 | } 76 | 77 | @SuppressWarnings("unchecked") 78 | @NotNull 79 | @Override 80 | public T create(@NotNull Class resultClass) { 81 | if (resultClass == CodingNetPullRequest.class) { 82 | return (T)createPullRequest(); 83 | } 84 | 85 | throw new ClassCastException(this.getClass().getName() + ": bad class type: " + resultClass.getName()); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetIssue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import com.intellij.openapi.util.text.StringUtil; 19 | import org.jetbrains.annotations.NotNull; 20 | import org.jetbrains.annotations.Nullable; 21 | 22 | import java.util.Date; 23 | 24 | /** 25 | * @author Aleksey Pivovarov 26 | */ 27 | public class CodingNetIssue { 28 | @NotNull private final String myHtmlUrl; 29 | private final long myNumber; 30 | @NotNull private final String myState; 31 | @NotNull private final String myTitle; 32 | @NotNull private final String myBody; 33 | 34 | @NotNull private final CodingNetUser myUser; 35 | @Nullable private final CodingNetUser myAssignee; 36 | 37 | @Nullable private final Date myClosedAt; 38 | @NotNull private final Date myCreatedAt; 39 | @NotNull private final Date myUpdatedAt; 40 | 41 | public CodingNetIssue(@NotNull String htmlUrl, 42 | long number, 43 | @NotNull String state, 44 | @NotNull String title, 45 | @Nullable String body, 46 | @NotNull CodingNetUser user, 47 | @Nullable CodingNetUser assignee, 48 | @Nullable Date closedAt, 49 | @NotNull Date createdAt, 50 | @NotNull Date updatedAt) { 51 | myHtmlUrl = htmlUrl; 52 | myNumber = number; 53 | myState = state; 54 | myTitle = title; 55 | myBody = StringUtil.notNullize(body); 56 | myUser = user; 57 | myAssignee = assignee; 58 | myClosedAt = closedAt; 59 | myCreatedAt = createdAt; 60 | myUpdatedAt = updatedAt; 61 | } 62 | 63 | @NotNull 64 | public String getHtmlUrl() { 65 | return myHtmlUrl; 66 | } 67 | 68 | public long getNumber() { 69 | return myNumber; 70 | } 71 | 72 | @NotNull 73 | public String getState() { 74 | return myState; 75 | } 76 | 77 | @NotNull 78 | public String getTitle() { 79 | return myTitle; 80 | } 81 | 82 | @NotNull 83 | public String getBody() { 84 | return myBody; 85 | } 86 | 87 | @NotNull 88 | public CodingNetUser getUser() { 89 | return myUser; 90 | } 91 | 92 | @Nullable 93 | public CodingNetUser getAssignee() { 94 | return myAssignee; 95 | } 96 | 97 | @Nullable 98 | public Date getClosedAt() { 99 | return myClosedAt; 100 | } 101 | 102 | @NotNull 103 | public Date getCreatedAt() { 104 | return myCreatedAt; 105 | } 106 | 107 | @NotNull 108 | public Date getUpdatedAt() { 109 | return myUpdatedAt; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetUserDetailed.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | import org.jetbrains.annotations.Nullable; 20 | 21 | /** 22 | * @author robin 23 | */ 24 | public class CodingNetUserDetailed extends CodingNetUser { 25 | @Nullable private String myName; 26 | @Nullable private String myEmail; 27 | 28 | @Nullable private Integer myOwnedPrivateRepos; 29 | 30 | @Nullable private String myType; 31 | @Nullable private UserPlan myPlan; 32 | 33 | /** 34 | * 用户信息详情 35 | */ 36 | private Data myData; 37 | 38 | public static class Data{ 39 | private String myName; 40 | 41 | public Data(String name){ 42 | this.myName=name; 43 | } 44 | } 45 | 46 | 47 | public static class UserPlan { 48 | @NotNull private final String myName; 49 | private final long myPrivateRepos; 50 | 51 | public UserPlan(@NotNull String name, long privateRepos) { 52 | myName = name; 53 | myPrivateRepos = privateRepos; 54 | } 55 | 56 | @NotNull 57 | public String getName() { 58 | return myName; 59 | } 60 | 61 | public long getPrivateRepos() { 62 | return myPrivateRepos; 63 | } 64 | } 65 | 66 | public boolean canCreatePrivateRepo() { 67 | return getPlan() == null || getOwnedPrivateRepos() == null || getPlan().getPrivateRepos() > getOwnedPrivateRepos(); 68 | } 69 | 70 | public CodingNetUserDetailed(){ 71 | 72 | } 73 | 74 | 75 | public CodingNetUserDetailed(Data data){ 76 | this.myData=data; 77 | } 78 | 79 | 80 | public CodingNetUserDetailed(@NotNull String login, 81 | @NotNull String htmlUrl, 82 | @Nullable String avatarUrl, 83 | @Nullable String name, 84 | @Nullable String email, 85 | @Nullable Integer ownedPrivateRepos, 86 | @Nullable String type, 87 | @Nullable UserPlan plan) { 88 | super(login, htmlUrl, avatarUrl); 89 | myName = name; 90 | myEmail = email; 91 | myOwnedPrivateRepos = ownedPrivateRepos; 92 | myType = type; 93 | myPlan = plan; 94 | } 95 | 96 | @Nullable 97 | public String getName() { 98 | return myName; 99 | } 100 | 101 | @Nullable 102 | public String getEmail() { 103 | return myEmail; 104 | } 105 | 106 | @Nullable 107 | public String getType() { 108 | return myType; 109 | } 110 | 111 | @Nullable 112 | public Integer getOwnedPrivateRepos() { 113 | return myOwnedPrivateRepos; 114 | } 115 | 116 | @Nullable 117 | public UserPlan getPlan() { 118 | return myPlan; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetRepo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import com.intellij.openapi.util.text.StringUtil; 19 | import org.jetbrains.annotations.NotNull; 20 | import org.jetbrains.annotations.Nullable; 21 | 22 | 23 | public class CodingNetRepo { 24 | @NotNull 25 | private String myName; 26 | @NotNull 27 | private String myDescription; 28 | 29 | private boolean myIsPrivate; 30 | private boolean myIsFork; 31 | 32 | @NotNull 33 | private String myHtmlUrl; 34 | @NotNull 35 | private String myCloneUrl; 36 | 37 | @Nullable 38 | private String myDefaultBranch; 39 | 40 | @NotNull 41 | private CodingNetUser myOwner; 42 | 43 | private String myHttpsUrl; 44 | 45 | public CodingNetRepo(String httpsUrl) { 46 | myHttpsUrl = httpsUrl; 47 | } 48 | 49 | public String getHttpsUrl() { 50 | return myHttpsUrl; 51 | } 52 | 53 | public CodingNetRepo(@NotNull String name, 54 | @Nullable String description, 55 | boolean isPrivate, 56 | boolean isFork, 57 | @NotNull String htmlUrl, 58 | @NotNull String cloneUrl, 59 | @Nullable String defaultBranch, 60 | @NotNull CodingNetUser owner) { 61 | myName = name; 62 | myDescription = StringUtil.notNullize(description); 63 | myIsPrivate = isPrivate; 64 | myIsFork = isFork; 65 | myHtmlUrl = htmlUrl; 66 | myCloneUrl = cloneUrl; 67 | myDefaultBranch = defaultBranch; 68 | myOwner = owner; 69 | } 70 | 71 | @NotNull 72 | public String getName() { 73 | return myName; 74 | } 75 | 76 | @NotNull 77 | public String getFullName() { 78 | return getUserName() + "/" + getName(); 79 | } 80 | 81 | @NotNull 82 | public String getDescription() { 83 | return myDescription; 84 | } 85 | 86 | public boolean isPrivate() { 87 | return myIsPrivate; 88 | } 89 | 90 | public boolean isFork() { 91 | return myIsFork; 92 | } 93 | 94 | @NotNull 95 | public String getHtmlUrl() { 96 | return myHtmlUrl; 97 | } 98 | 99 | @NotNull 100 | public String getCloneUrl() { 101 | return myCloneUrl; 102 | } 103 | 104 | @Nullable 105 | public String getDefaultBranch() { 106 | return myDefaultBranch; 107 | } 108 | 109 | @NotNull 110 | public CodingNetUser getOwner() { 111 | return myOwner; 112 | } 113 | 114 | @NotNull 115 | public String getUserName() { 116 | return getOwner().getLogin(); 117 | } 118 | 119 | @NotNull 120 | public CodingNetFullPath getFullPath() { 121 | return new CodingNetFullPath(getUserName(), getName()); 122 | } 123 | } 124 | 125 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetCommit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | import org.jetbrains.annotations.Nullable; 20 | 21 | import java.util.Date; 22 | import java.util.List; 23 | 24 | /** 25 | * @author robin 26 | */ 27 | @SuppressWarnings("UnusedDeclaration") 28 | public class CodingNetCommit extends CodingNetCommitSha { 29 | @Nullable private final CodingNetUser myAuthor; 30 | @Nullable private final CodingNetUser myCommitter; 31 | 32 | @NotNull private final List myParents; 33 | 34 | @NotNull private final GitCommit myCommit; 35 | 36 | public static class GitCommit { 37 | @NotNull private final String myMessage; 38 | 39 | @NotNull private final GitUser myAuthor; 40 | @NotNull private final GitUser myCommitter; 41 | 42 | public GitCommit(@NotNull String message, @NotNull GitUser author, @NotNull GitUser committer) { 43 | myMessage = message; 44 | myAuthor = author; 45 | myCommitter = committer; 46 | } 47 | 48 | @NotNull 49 | public String getMessage() { 50 | return myMessage; 51 | } 52 | 53 | @NotNull 54 | public GitUser getAuthor() { 55 | return myAuthor; 56 | } 57 | 58 | @NotNull 59 | public GitUser getCommitter() { 60 | return myCommitter; 61 | } 62 | } 63 | 64 | public static class GitUser { 65 | @NotNull private final String myName; 66 | @NotNull private final String myEmail; 67 | @NotNull private final Date myDate; 68 | 69 | public GitUser(@NotNull String name, @NotNull String email, @NotNull Date date) { 70 | myName = name; 71 | myEmail = email; 72 | myDate = date; 73 | } 74 | 75 | @NotNull 76 | public String getName() { 77 | return myName; 78 | } 79 | 80 | @NotNull 81 | public String getEmail() { 82 | return myEmail; 83 | } 84 | 85 | @NotNull 86 | public Date getDate() { 87 | return myDate; 88 | } 89 | } 90 | 91 | public CodingNetCommit(@NotNull String url, 92 | @NotNull String sha, 93 | @Nullable CodingNetUser author, 94 | @Nullable CodingNetUser committer, 95 | @NotNull List parents, 96 | @NotNull GitCommit commit) { 97 | super(url, sha); 98 | myAuthor = author; 99 | myCommitter = committer; 100 | myParents = parents; 101 | myCommit = commit; 102 | } 103 | 104 | @Nullable 105 | public CodingNetUser getAuthor() { 106 | return myAuthor; 107 | } 108 | 109 | @Nullable 110 | public CodingNetUser getCommitter() { 111 | return myCommitter; 112 | } 113 | 114 | @NotNull 115 | public List getParents() { 116 | return myParents; 117 | } 118 | 119 | @NotNull 120 | public GitCommit getCommit() { 121 | return myCommit; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetUserRaw.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | import org.jetbrains.annotations.Nullable; 20 | 21 | /** 22 | * 23 | */ 24 | @SuppressWarnings("UnusedDeclaration") 25 | class CodingNetUserRaw implements ICodingNetDataConstructor { 26 | 27 | @Nullable public String login; 28 | @Nullable public Long id; 29 | 30 | @Nullable public String url; 31 | @Nullable public String htmlUrl; 32 | 33 | // @Nullable public String name; 34 | // @Nullable public String email; 35 | // @Nullable public String company; 36 | // @Nullable public String location; 37 | // @Nullable public String type; 38 | // 39 | // @Nullable public Integer publicRepos; 40 | // @Nullable public Integer publicGists; 41 | // @Nullable public Integer totalPrivateRepos; 42 | // @Nullable public Integer ownedPrivateRepos; 43 | // @Nullable public Integer privateGists; 44 | // @Nullable public Long diskUsage; 45 | // 46 | // @Nullable public Integer followers; 47 | // @Nullable public Integer following; 48 | @Nullable public String avatarUrl; 49 | // @Nullable public String gravatarId; 50 | // @Nullable public Integer collaborators; 51 | // @Nullable public String blog; 52 | // 53 | // @Nullable public UserPlanRaw plan; 54 | 55 | // @Nullable public Date createdAt; 56 | 57 | @Nullable public Data data; 58 | 59 | public static class Data{ 60 | public String name; 61 | 62 | /** 63 | * 构建用户详情对象 64 | * @return 65 | */ 66 | public CodingNetUserDetailed.Data create(){ 67 | return new CodingNetUserDetailed.Data(name); 68 | } 69 | 70 | } 71 | 72 | 73 | public static class UserPlanRaw { 74 | @Nullable public String name; 75 | @Nullable public Long space; 76 | @Nullable public Long collaborators; 77 | @Nullable public Long privateRepos; 78 | 79 | @SuppressWarnings("ConstantConditions") 80 | @NotNull 81 | public CodingNetUserDetailed.UserPlan create() { 82 | return new CodingNetUserDetailed.UserPlan(name, privateRepos); 83 | } 84 | } 85 | 86 | @SuppressWarnings("ConstantConditions") 87 | @NotNull 88 | public CodingNetUser createUser() { 89 | return new CodingNetUser(login, htmlUrl, avatarUrl); 90 | } 91 | 92 | @SuppressWarnings("ConstantConditions") 93 | @NotNull 94 | public CodingNetUserDetailed createUserDetailed() { 95 | CodingNetUserDetailed.Data data = this.data == null ? null : this.data.create(); 96 | // return new CodingNetUserDetailed(login, htmlUrl, avatarUrl, name, email, ownedPrivateRepos, type, plan); 97 | return new CodingNetUserDetailed(data); 98 | } 99 | 100 | @SuppressWarnings("unchecked") 101 | @NotNull 102 | @Override 103 | public T create(@NotNull Class resultClass) { 104 | // if (resultClass == CodingNetUser.class) { 105 | // return (T)createUser(); 106 | // } 107 | if (resultClass == CodingNetUserDetailed.class) { 108 | return (T)createUserDetailed(); 109 | } 110 | 111 | throw new ClassCastException(this.getClass().getName() + ": bad class type: " + resultClass.getName()); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/org/coding/git/check/CodingNetGitCloneDialog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.check; 17 | 18 | import com.intellij.dvcs.DvcsRememberedInputs; 19 | import com.intellij.dvcs.hosting.RepositoryHostingService; 20 | import com.intellij.dvcs.hosting.RepositoryListLoader; 21 | import com.intellij.dvcs.hosting.RepositoryListLoadingException; 22 | import com.intellij.openapi.progress.ProgressIndicator; 23 | import com.intellij.openapi.project.Project; 24 | import com.intellij.ui.EditorComboBox; 25 | import com.intellij.ui.TextFieldWithAutoCompletion; 26 | import git4idea.checkout.GitCloneDialog; 27 | import org.coding.git.api.CodingNetRepo; 28 | import org.jetbrains.annotations.NotNull; 29 | 30 | import javax.swing.*; 31 | import java.util.Collection; 32 | import java.util.Collections; 33 | import java.util.List; 34 | import java.util.stream.Collectors; 35 | 36 | /** 37 | * Created by robin on 16/8/17. 38 | */ 39 | public class CodingNetGitCloneDialog extends GitCloneDialog { 40 | 41 | private List availableRepos; 42 | 43 | public CodingNetGitCloneDialog(@NotNull Project project) { 44 | super(project, null); 45 | } 46 | 47 | public CodingNetGitCloneDialog(Project project, List availableRepos) { 48 | this(project); 49 | this.availableRepos = availableRepos; 50 | } 51 | 52 | public void cleanCacheModel() { 53 | JComponent preferredFocusedComponent = getPreferredFocusedComponent(); 54 | if (preferredFocusedComponent instanceof EditorComboBox) { 55 | ((EditorComboBox) getPreferredFocusedComponent()).removeAllItems(); 56 | return; 57 | } 58 | if (preferredFocusedComponent instanceof TextFieldWithAutoCompletion) { 59 | TextFieldWithAutoCompletion textFieldWithAutoCompletion = (TextFieldWithAutoCompletion) preferredFocusedComponent; 60 | textFieldWithAutoCompletion.removeAll(); 61 | } 62 | } 63 | 64 | public void rememberSettings() { 65 | 66 | } 67 | 68 | @NotNull 69 | @Override 70 | protected Collection getRepositoryHostingServices() { 71 | return Collections.singletonList(new CodingNetRepositoryHostingService()); 72 | } 73 | 74 | public class CodingNetRepositoryHostingService implements RepositoryHostingService, RepositoryListLoader { 75 | 76 | @NotNull 77 | @Override 78 | public String getServiceDisplayName() { 79 | return "Coding.net"; 80 | } 81 | 82 | @NotNull 83 | @Override 84 | public RepositoryListLoader getRepositoryListLoader(@NotNull Project project) { 85 | return this; 86 | } 87 | 88 | @Override 89 | public boolean isEnabled() { 90 | return true; 91 | } 92 | 93 | @Override 94 | public boolean enable() { 95 | return true; 96 | } 97 | 98 | @NotNull 99 | @Override 100 | public List getAvailableRepositories(@NotNull ProgressIndicator progressIndicator) throws RepositoryListLoadingException { 101 | return availableRepos.stream().map(CodingNetRepo::getHttpsUrl).collect(Collectors.toList()); 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/org/coding/git/providers/CodingNetCheckoutProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.providers; 17 | 18 | import com.intellij.openapi.components.ServiceManager; 19 | import com.intellij.openapi.project.Project; 20 | import com.intellij.openapi.vcs.CheckoutProvider; 21 | import com.intellij.openapi.vfs.LocalFileSystem; 22 | import com.intellij.openapi.vfs.VirtualFile; 23 | import git4idea.actions.BasicAction; 24 | import git4idea.checkout.GitCheckoutProvider; 25 | import git4idea.checkout.GitCloneDialog; 26 | import git4idea.commands.Git; 27 | import org.coding.git.api.CodingNetApiUtil; 28 | import org.coding.git.check.CodingNetGitCloneDialog; 29 | import org.jetbrains.annotations.NotNull; 30 | import org.jetbrains.annotations.Nullable; 31 | import org.coding.git.api.CodingNetRepo; 32 | import org.coding.git.util.CodingNetAuthDataHolder; 33 | import org.coding.git.util.CodingNetNotifications; 34 | import org.coding.git.util.CodingNetUtil; 35 | 36 | import java.io.File; 37 | import java.io.IOException; 38 | import java.util.List; 39 | 40 | 41 | /** 42 | * Based on https://github.com/JetBrains/intellij-community/blob/master/plugins/github/src/org/jetbrains/plugins/github/extensions/GithubCheckoutProvider.java 43 | * @author JetBrains s.r.o. 44 | * @author oleg 45 | * @author robin 46 | */ 47 | public class CodingNetCheckoutProvider implements CheckoutProvider { 48 | 49 | public CodingNetCheckoutProvider() { 50 | 51 | } 52 | 53 | 54 | @Override 55 | public void doCheckout(@NotNull final Project project, @Nullable final Listener listener) { 56 | //--检测Git环境 57 | if (!CodingNetUtil.testGitExecutable(project)) { 58 | return; 59 | } 60 | BasicAction.saveAll(); 61 | 62 | List availableRepos; 63 | try { 64 | //--获取有效资源 65 | availableRepos = CodingNetUtil.computeValueInModalIO(project, "Access to Coding.net", indicator -> 66 | CodingNetUtil.runTask(project, CodingNetAuthDataHolder.createFromSettings(), indicator, CodingNetApiUtil::getAvailableRepos)); 67 | } catch (IOException e) { 68 | CodingNetNotifications.showError(project, "Couldn't get the list of Coding.net repositories", e); 69 | return; 70 | } 71 | // Collections.sort(availableRepos, (r1, r2) -> { 72 | // final int comparedOwners = r1.getUserName().compareTo(r2.getUserName()); 73 | // return comparedOwners != 0 ? comparedOwners : r1.getName().compareTo(r2.getName()); 74 | // }); 75 | 76 | final CodingNetGitCloneDialog dialog = new CodingNetGitCloneDialog(project, availableRepos); 77 | dialog.cleanCacheModel(); 78 | if (!dialog.showAndGet()) { 79 | return; 80 | } 81 | dialog.rememberSettings(); 82 | final VirtualFile destinationParent = LocalFileSystem.getInstance().findFileByIoFile(new File(dialog.getParentDirectory())); 83 | if (destinationParent == null) { 84 | return; 85 | } 86 | final String sourceRepositoryURL = dialog.getSourceRepositoryURL(); 87 | final String directoryName = dialog.getDirectoryName(); 88 | final String parentDirectory = dialog.getParentDirectory(); 89 | 90 | Git git = ServiceManager.getService(Git.class); 91 | GitCheckoutProvider.clone(project, git, listener, destinationParent, sourceRepositoryURL, directoryName, parentDirectory); 92 | } 93 | 94 | @Override 95 | public String getVcsName() { 96 | return "Coding.net"; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetGist.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import com.intellij.openapi.util.text.StringUtil; 19 | import org.jetbrains.annotations.NotNull; 20 | import org.jetbrains.annotations.Nullable; 21 | 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | 25 | 26 | public class CodingNetGist { 27 | @NotNull private final String myId; 28 | @NotNull private final String myDescription; 29 | 30 | private final boolean myIsPublic; 31 | 32 | @NotNull private final String myHtmlUrl; 33 | 34 | @NotNull private final List myFiles; 35 | 36 | @Nullable private final CodingNetUser myUser; 37 | 38 | public static class GistFile { 39 | @NotNull private final String myFilename; 40 | @NotNull private final String myContent; 41 | 42 | @NotNull private final String myRawUrl; 43 | 44 | public GistFile(@NotNull String filename, @NotNull String content, @NotNull String rawUrl) { 45 | myFilename = filename; 46 | myContent = content; 47 | myRawUrl = rawUrl; 48 | } 49 | 50 | @NotNull 51 | public String getFilename() { 52 | return myFilename; 53 | } 54 | 55 | @NotNull 56 | public String getContent() { 57 | return myContent; 58 | } 59 | 60 | @NotNull 61 | public String getRawUrl() { 62 | return myRawUrl; 63 | } 64 | } 65 | 66 | @NotNull 67 | public List getContent() { 68 | List ret = new ArrayList(); 69 | for (GistFile file : getFiles()) { 70 | ret.add(new FileContent(file.getFilename(), file.getContent())); 71 | } 72 | return ret; 73 | } 74 | 75 | public CodingNetGist(@NotNull String id, 76 | @Nullable String description, 77 | boolean isPublic, 78 | @NotNull String htmlUrl, 79 | @NotNull List files, 80 | @Nullable CodingNetUser user) { 81 | myId = id; 82 | myDescription = StringUtil.notNullize(description); 83 | myIsPublic = isPublic; 84 | myHtmlUrl = htmlUrl; 85 | myFiles = files; 86 | myUser = user; 87 | } 88 | 89 | @NotNull 90 | public String getId() { 91 | return myId; 92 | } 93 | 94 | @NotNull 95 | public String getDescription() { 96 | return myDescription; 97 | } 98 | 99 | public boolean isPublic() { 100 | return myIsPublic; 101 | } 102 | 103 | @NotNull 104 | public String getHtmlUrl() { 105 | return myHtmlUrl; 106 | } 107 | 108 | @NotNull 109 | public List getFiles() { 110 | return myFiles; 111 | } 112 | 113 | @Nullable 114 | public CodingNetUser getUser() { 115 | return myUser; 116 | } 117 | 118 | public static class FileContent { 119 | @NotNull private final String myFileName; 120 | @NotNull private final String myContent; 121 | 122 | public FileContent(@NotNull String fileName, @NotNull String content) { 123 | myFileName = fileName; 124 | myContent = content; 125 | } 126 | 127 | @NotNull 128 | public String getFileName() { 129 | return myFileName; 130 | } 131 | 132 | @NotNull 133 | public String getContent() { 134 | return myContent; 135 | } 136 | 137 | @Override 138 | public boolean equals(Object o) { 139 | if (this == o) return true; 140 | if (o == null || getClass() != o.getClass()) return false; 141 | 142 | FileContent that = (FileContent)o; 143 | 144 | if (!myContent.equals(that.myContent)) return false; 145 | if (!myFileName.equals(that.myFileName)) return false; 146 | 147 | return true; 148 | } 149 | 150 | @Override 151 | public int hashCode() { 152 | int result = myFileName.hashCode(); 153 | result = 31 * result + myContent.hashCode(); 154 | return result; 155 | } 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /src/org/coding/git/ui/CodingNetLoginDialog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.ui; 17 | 18 | import com.intellij.openapi.diagnostic.Logger; 19 | import com.intellij.openapi.project.Project; 20 | import com.intellij.openapi.ui.DialogWrapper; 21 | import org.coding.git.util.CodingNetSettings; 22 | import org.coding.git.util.CodingNetUtil; 23 | import org.jetbrains.annotations.NotNull; 24 | import org.coding.git.util.CodingNetAuthData; 25 | import org.coding.git.util.CodingNetAuthDataHolder; 26 | 27 | import javax.swing.*; 28 | import java.io.IOException; 29 | 30 | /** 31 | * @author robin 32 | * Based on https://github.com/JetBrains/intellij-community/blob/master/plugins/github/src/org/jetbrains/plugins/github/ui/GithubLoginDialog.java 33 | * @author JetBrains s.r.o. 34 | * @author oleg 35 | * @date 10/20/10 36 | */ 37 | public class CodingNetLoginDialog extends DialogWrapper { 38 | 39 | protected static final Logger LOG = CodingNetUtil.LOG; 40 | 41 | protected final CodingNetLoginPanel myCodingNetLoginPanel; 42 | protected final CodingNetSettings mySettings; 43 | 44 | protected final Project myProject; 45 | 46 | protected CodingNetAuthData myAuthData; 47 | 48 | public CodingNetLoginDialog(@NotNull final Project project, @NotNull CodingNetAuthData oldAuthData) { 49 | super(project, true); 50 | myProject = project; 51 | 52 | myCodingNetLoginPanel = new CodingNetLoginPanel(this); 53 | 54 | myCodingNetLoginPanel.setHost(oldAuthData.getHost()); 55 | myCodingNetLoginPanel.setAuthType(oldAuthData.getAuthType()); 56 | CodingNetAuthData.BasicAuth basicAuth = oldAuthData.getBasicAuth(); 57 | if (basicAuth != null) { 58 | myCodingNetLoginPanel.setLogin(basicAuth.getLogin()); 59 | } 60 | 61 | mySettings = CodingNetSettings.getInstance(); 62 | if (mySettings.isSavePasswordMakesSense()) { 63 | myCodingNetLoginPanel.setSavePasswordSelected(mySettings.isSavePassword()); 64 | } 65 | else { 66 | myCodingNetLoginPanel.setSavePasswordVisibleEnabled(false); 67 | } 68 | 69 | setTitle("Login to coding.net"); 70 | setOKButtonText("Login"); 71 | init(); 72 | } 73 | 74 | @NotNull 75 | protected Action[] createActions() { 76 | return new Action[]{getOKAction(), getCancelAction(), getHelpAction()}; 77 | } 78 | 79 | @Override 80 | protected JComponent createCenterPanel() { 81 | return myCodingNetLoginPanel.getPanel(); 82 | } 83 | 84 | @Override 85 | protected String getHelpId() { 86 | return "login_to_coding"; 87 | } 88 | 89 | @Override 90 | public JComponent getPreferredFocusedComponent() { 91 | return myCodingNetLoginPanel.getPreferableFocusComponent(); 92 | } 93 | 94 | @Override 95 | protected void doOKAction() { 96 | final CodingNetAuthDataHolder authHolder = new CodingNetAuthDataHolder(myCodingNetLoginPanel.getAuthData()); 97 | try { 98 | CodingNetUtil.computeValueInModalIO(myProject, "Access to Coding.net", indicator -> 99 | CodingNetUtil.checkAuthData(myProject, authHolder, indicator)); 100 | 101 | myAuthData = authHolder.getAuthData(); 102 | 103 | if (mySettings.isSavePasswordMakesSense()) { 104 | mySettings.setSavePassword(myCodingNetLoginPanel.isSavePasswordSelected()); 105 | } 106 | super.doOKAction(); 107 | } 108 | catch (IOException e) { 109 | LOG.info(e); 110 | setErrorText("Can't login: " + CodingNetUtil.getErrorTextFromException(e)); 111 | } 112 | } 113 | 114 | public boolean isSavePasswordSelected() { 115 | return myCodingNetLoginPanel.isSavePasswordSelected(); 116 | } 117 | 118 | @NotNull 119 | public CodingNetAuthData getAuthData() { 120 | if (myAuthData == null) { 121 | throw new IllegalStateException("AuthData is not set"); 122 | } 123 | return myAuthData; 124 | } 125 | 126 | public void clearErrors() { 127 | setErrorText(null); 128 | } 129 | } -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetCommitRaw.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | import org.jetbrains.annotations.Nullable; 20 | 21 | import java.util.ArrayList; 22 | import java.util.Date; 23 | import java.util.List; 24 | 25 | 26 | @SuppressWarnings("UnusedDeclaration") 27 | class CodingNetCommitRaw implements ICodingNetDataConstructor { 28 | @Nullable public String url; 29 | @Nullable public String sha; 30 | 31 | @Nullable public CodingNetUserRaw author; 32 | @Nullable public CodingNetUserRaw committer; 33 | 34 | @Nullable public GitCommitRaw commit; 35 | 36 | @Nullable public CommitStatsRaw stats; 37 | @Nullable public List files; 38 | 39 | @Nullable public List parents; 40 | 41 | public static class GitCommitRaw { 42 | @Nullable public String url; 43 | @Nullable public String message; 44 | 45 | @Nullable public GitUserRaw author; 46 | @Nullable public GitUserRaw committer; 47 | 48 | @SuppressWarnings("ConstantConditions") 49 | @NotNull 50 | public CodingNetCommit.GitCommit create() { 51 | return new CodingNetCommit.GitCommit(message, author.create(), committer.create()); 52 | } 53 | } 54 | 55 | public static class GitUserRaw { 56 | @Nullable public String name; 57 | @Nullable public String email; 58 | @Nullable public Date date; 59 | 60 | @SuppressWarnings("ConstantConditions") 61 | @NotNull 62 | public CodingNetCommit.GitUser create() { 63 | return new CodingNetCommit.GitUser(name, email, date); 64 | } 65 | } 66 | 67 | public static class CommitStatsRaw { 68 | @Nullable public Integer additions; 69 | @Nullable public Integer deletions; 70 | @Nullable public Integer total; 71 | 72 | @SuppressWarnings("ConstantConditions") 73 | @NotNull 74 | public CodingNetCommitDetailed.CommitStats create() { 75 | return new CodingNetCommitDetailed.CommitStats(additions, deletions, total); 76 | } 77 | } 78 | 79 | @SuppressWarnings("ConstantConditions") 80 | @NotNull 81 | public CodingNetCommitSha createCommitSha() { 82 | return new CodingNetCommitSha(url, sha); 83 | } 84 | 85 | @SuppressWarnings("ConstantConditions") 86 | @NotNull 87 | public CodingNetCommit createCommit() { 88 | CodingNetUser author = this.author == null ? null : this.author.createUser(); 89 | CodingNetUser committer = this.committer == null ? null : this.committer.createUser(); 90 | 91 | List parents = new ArrayList(); 92 | for (CodingNetCommitRaw raw : this.parents) { 93 | parents.add(raw.createCommitSha()); 94 | } 95 | return new CodingNetCommit(url, sha, author, committer, parents, commit.create()); 96 | } 97 | 98 | @SuppressWarnings("ConstantConditions") 99 | @NotNull 100 | public CodingNetCommitDetailed createCommitDetailed() { 101 | CodingNetCommit commit = createCommit(); 102 | List files = new ArrayList(); 103 | for (CodingNetFileRaw raw : this.files) { 104 | files.add(raw.createFile()); 105 | } 106 | 107 | return new CodingNetCommitDetailed(commit.getUrl(), commit.getSha(), commit.getAuthor(), commit.getCommitter(), commit.getParents(), 108 | commit.getCommit(), stats.create(), files); 109 | } 110 | 111 | @SuppressWarnings("unchecked") 112 | @NotNull 113 | @Override 114 | public T create(@NotNull Class resultClass) { 115 | if (resultClass == CodingNetCommitSha.class) { 116 | return (T)createCommitSha(); 117 | } 118 | if (resultClass == CodingNetCommit.class) { 119 | return (T)createCommit(); 120 | } 121 | if (resultClass == CodingNetCommitDetailed.class) { 122 | return (T)createCommitDetailed(); 123 | } 124 | 125 | throw new ClassCastException(this.getClass().getName() + ": bad class type: " + resultClass.getName()); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetPullRequest.java: -------------------------------------------------------------------------------- 1 | package org.coding.git.api; 2 | 3 | import com.intellij.openapi.util.text.StringUtil; 4 | import org.jetbrains.annotations.NotNull; 5 | import org.jetbrains.annotations.Nullable; 6 | 7 | import java.util.Date; 8 | 9 | 10 | @SuppressWarnings("UnusedDeclaration") 11 | public class CodingNetPullRequest { 12 | private final long myNumber; 13 | @NotNull private final String myState; 14 | @NotNull private final String myTitle; 15 | @NotNull private final String myBodyHtml; 16 | 17 | @NotNull private final String myHtmlUrl; 18 | @NotNull private final String myDiffUrl; 19 | @NotNull private final String myPatchUrl; 20 | @NotNull private final String myIssueUrl; 21 | 22 | @NotNull private final Date myCreatedAt; 23 | @NotNull private final Date myUpdatedAt; 24 | @Nullable private final Date myClosedAt; 25 | @Nullable private final Date myMergedAt; 26 | 27 | @NotNull private final CodingNetUser myUser; 28 | 29 | @NotNull private final Link myHead; 30 | @NotNull private final Link myBase; 31 | 32 | public static class Link { 33 | @NotNull private final String myLabel; 34 | @NotNull private final String myRef; 35 | @NotNull private final String mySha; 36 | 37 | @NotNull private final CodingNetRepo myRepo; 38 | @NotNull private final CodingNetUser myUser; 39 | 40 | public Link(@NotNull String label, @NotNull String ref, @NotNull String sha, @NotNull CodingNetRepo repo, @NotNull CodingNetUser user) { 41 | myLabel = label; 42 | myRef = ref; 43 | mySha = sha; 44 | myRepo = repo; 45 | myUser = user; 46 | } 47 | 48 | @NotNull 49 | public String getLabel() { 50 | return myLabel; 51 | } 52 | 53 | @NotNull 54 | public String getRef() { 55 | return myRef; 56 | } 57 | 58 | @NotNull 59 | public String getSha() { 60 | return mySha; 61 | } 62 | 63 | @NotNull 64 | public CodingNetRepo getRepo() { 65 | return myRepo; 66 | } 67 | 68 | @NotNull 69 | public CodingNetUser getUser() { 70 | return myUser; 71 | } 72 | } 73 | 74 | public CodingNetPullRequest(long number, 75 | @NotNull String state, 76 | @NotNull String title, 77 | @Nullable String bodyHtml, 78 | @NotNull String htmlUrl, 79 | @NotNull String diffUrl, 80 | @NotNull String patchUrl, 81 | @NotNull String issueUrl, 82 | @NotNull Date createdAt, 83 | @NotNull Date updatedAt, 84 | @Nullable Date closedAt, 85 | @Nullable Date mergedAt, 86 | @NotNull CodingNetUser user, 87 | @NotNull Link head, 88 | @NotNull Link base) { 89 | myNumber = number; 90 | myState = state; 91 | myTitle = title; 92 | myBodyHtml = StringUtil.notNullize(bodyHtml); 93 | myHtmlUrl = htmlUrl; 94 | myDiffUrl = diffUrl; 95 | myPatchUrl = patchUrl; 96 | myIssueUrl = issueUrl; 97 | myCreatedAt = createdAt; 98 | myUpdatedAt = updatedAt; 99 | myClosedAt = closedAt; 100 | myMergedAt = mergedAt; 101 | myUser = user; 102 | myHead = head; 103 | myBase = base; 104 | } 105 | 106 | public long getNumber() { 107 | return myNumber; 108 | } 109 | 110 | @NotNull 111 | public String getState() { 112 | return myState; 113 | } 114 | 115 | @NotNull 116 | public String getTitle() { 117 | return myTitle; 118 | } 119 | 120 | @NotNull 121 | public String getBodyHtml() { 122 | return myBodyHtml; 123 | } 124 | 125 | @NotNull 126 | public String getHtmlUrl() { 127 | return myHtmlUrl; 128 | } 129 | 130 | @NotNull 131 | public String getDiffUrl() { 132 | return myDiffUrl; 133 | } 134 | 135 | @NotNull 136 | public String getPatchUrl() { 137 | return myPatchUrl; 138 | } 139 | 140 | @NotNull 141 | public String getIssueUrl() { 142 | return myIssueUrl; 143 | } 144 | 145 | @NotNull 146 | public Date getCreatedAt() { 147 | return myCreatedAt; 148 | } 149 | 150 | @NotNull 151 | public Date getUpdatedAt() { 152 | return myUpdatedAt; 153 | } 154 | 155 | @Nullable 156 | public Date getClosedAt() { 157 | return myClosedAt; 158 | } 159 | 160 | @Nullable 161 | public Date getMergedAt() { 162 | return myMergedAt; 163 | } 164 | 165 | @NotNull 166 | public CodingNetUser getUser() { 167 | return myUser; 168 | } 169 | 170 | @NotNull 171 | public Link getHead() { 172 | return myHead; 173 | } 174 | 175 | @NotNull 176 | public Link getBase() { 177 | return myBase; 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /.idea/markdown-navigator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 36 | 37 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /src/org/coding/git/api/CodingNetRepoRaw.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.api; 17 | 18 | import com.google.gson.annotations.SerializedName; 19 | import org.jetbrains.annotations.NotNull; 20 | 21 | /** 22 | * @author robin 23 | */ 24 | class CodingNetRepoRaw implements ICodingNetDataConstructor { 25 | // @Nullable public Long id; 26 | // @Nullable public String name; 27 | // @Nullable public String fullName; 28 | // @Nullable public String description; 29 | // 30 | // @SerializedName("private") 31 | // @Nullable public Boolean isPrivate; 32 | // @SerializedName("fork") 33 | // @Nullable public Boolean isFork; 34 | // 35 | // @Nullable public String url; 36 | // @Nullable public String htmlUrl; 37 | // @Nullable public String cloneUrl; 38 | // @Nullable public String gitUrl; 39 | // @Nullable public String sshUrl; 40 | // @Nullable public String svnUrl; 41 | // @Nullable public String mirrorUrl; 42 | // 43 | // @Nullable public String homepage; 44 | // @Nullable public String language; 45 | // @Nullable public Integer size; 46 | // 47 | // @Nullable public Integer forks; 48 | // @Nullable public Integer forksCount; 49 | // @Nullable public Integer watchers; 50 | // @Nullable public Integer watchersCount; 51 | // @Nullable public Integer openIssues; 52 | // @Nullable public Integer openIssuesCount; 53 | // 54 | // @Nullable public String masterBranch; 55 | // @Nullable public String defaultBranch; 56 | // 57 | // @Nullable public Boolean hasIssues; 58 | // @Nullable public Boolean hasWiki; 59 | // @Nullable public Boolean hasDownloads; 60 | // 61 | // @Nullable public CodingNetRepoRaw parent; 62 | // @Nullable public CodingNetRepoRaw source; 63 | // 64 | // @Nullable public CodingNetUserRaw owner; 65 | // @Nullable public CodingNetUserRaw organization; 66 | // 67 | // @Nullable public Date pushedAt; 68 | // @Nullable public Date createdAt; 69 | // @Nullable public Date updatedAt; 70 | 71 | //@Nullable public Permissions permissions; 72 | 73 | // public Data data; 74 | 75 | 76 | //public static class Data{ 77 | //List projects; 78 | //} 79 | 80 | // public static class Project{ 81 | @SerializedName("https_url") 82 | String httpsUrl; 83 | // } 84 | 85 | 86 | 87 | 88 | // public static class Permissions { 89 | // @Nullable public Boolean admin; 90 | // @Nullable public Boolean pull; 91 | // @Nullable public Boolean push; 92 | // 93 | // @SuppressWarnings("ConstantConditions") 94 | // @NotNull 95 | // public CodingNetRepoOrg.Permissions create() { 96 | // return new CodingNetRepoOrg.Permissions(admin, pull, push); 97 | // } 98 | // } 99 | 100 | 101 | @SuppressWarnings("ConstantConditions") 102 | @NotNull 103 | public CodingNetRepo createRepo() { 104 | //return new CodingNetRepo(name, description, isPrivate, isFork, htmlUrl, cloneUrl, defaultBranch, owner.createUser()); 105 | return new CodingNetRepo(httpsUrl); 106 | } 107 | 108 | // @SuppressWarnings("ConstantConditions") 109 | // @NotNull 110 | // public CodingNetRepoOrg createRepoOrg() { 111 | // return new CodingNetRepoOrg(name, description, isPrivate, isFork, htmlUrl, cloneUrl, defaultBranch, owner.createUser(), 112 | // permissions.create()); 113 | // } 114 | 115 | // @SuppressWarnings("ConstantConditions") 116 | // @NotNull 117 | // public CodingNetRepoDetailed createRepoDetailed() { 118 | // CodingNetRepo parent = this.parent == null ? null : this.parent.createRepo(); 119 | // CodingNetRepo source = this.source == null ? null : this.source.createRepo(); 120 | // return new CodingNetRepoDetailed(name, description, isPrivate, isFork, htmlUrl, cloneUrl, defaultBranch, owner.createUser(), 121 | // parent, source); 122 | // } 123 | 124 | @SuppressWarnings("unchecked") 125 | @NotNull 126 | @Override 127 | public T create(@NotNull Class resultClass) { 128 | if (resultClass == CodingNetRepo.class) { 129 | return (T)createRepo(); 130 | } 131 | // if (resultClass == CodingNetRepoOrg.class) { 132 | // return (T)createRepoOrg(); 133 | // } 134 | // if (resultClass == CodingNetRepoDetailed.class) { 135 | // return (T)createRepoDetailed(); 136 | // } 137 | 138 | throw new ClassCastException(this.getClass().getName() + ": bad class type: " + resultClass.getName()); 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /src/org/coding/git/CodingNetOpenAPICodeMsg.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.coding.git; 18 | 19 | import com.google.gson.annotations.SerializedName; 20 | 21 | /** 22 | * @author robin 23 | */ 24 | public enum CodingNetOpenAPICodeMsg { 25 | 26 | USER_PASSWORD_NO_CORRECT(1, UserPasswordNoCorrect.class), 27 | NEED_VERIFICATION_CODE(903, NeedVerificationCode.class), 28 | NO_LOGIN(1000, NoLogin.class), 29 | NO_EXIST_USER(1001, NoExistUser.class), 30 | LOGIN_EXPIRED(1029, LoginExpired.class), 31 | AUTH_ERROR(1402, AuthError.class), 32 | NEED_TWO_FACTOR_AUTH_CODE(3205, null), 33 | TWO_FACTOR_AUTH_CODE_REQUIRED(3209, null), 34 | USER_LOCKED(1009, UserLocked.class); 35 | 36 | 37 | private int code; 38 | 39 | 40 | private Class clazz; 41 | 42 | CodingNetOpenAPICodeMsg(int code, Class clazz) { 43 | this.code = code; 44 | this.clazz = clazz; 45 | 46 | } 47 | 48 | public Class getClazz() { 49 | return clazz; 50 | } 51 | 52 | public int getCode() { 53 | return code; 54 | } 55 | 56 | public interface ICodingNetOpenAPICodeMsg { 57 | String getMessage(); 58 | } 59 | 60 | 61 | /** 62 | * 2步认证失败 63 | */ 64 | class AuthError implements ICodingNetOpenAPICodeMsg { 65 | int code; 66 | AuthErrorCodeMsg msg; 67 | 68 | @Override 69 | public String getMessage() { 70 | return msg.toString(); 71 | } 72 | 73 | class AuthErrorCodeMsg { 74 | @SerializedName("auth_error") 75 | String authError; 76 | 77 | @Override 78 | public String toString() { 79 | return authError; 80 | } 81 | } 82 | } 83 | 84 | /** 85 | * 用户锁定 86 | */ 87 | class UserLocked implements ICodingNetOpenAPICodeMsg { 88 | int code; 89 | UserLockedCodeMsg msg; 90 | 91 | @Override 92 | public String getMessage() { 93 | return msg.toString(); 94 | } 95 | 96 | class UserLockedCodeMsg { 97 | @SerializedName("account") 98 | String account; 99 | 100 | @Override 101 | public String toString() { 102 | return account; 103 | } 104 | } 105 | } 106 | 107 | 108 | /** 109 | * 用户登陆超时 110 | */ 111 | class LoginExpired implements ICodingNetOpenAPICodeMsg { 112 | int code; 113 | LoginExpiredCodeMsg msg; 114 | 115 | @Override 116 | public String getMessage() { 117 | return msg.toString(); 118 | } 119 | 120 | class LoginExpiredCodeMsg { 121 | @SerializedName("user_login_status_expired") 122 | String loginStatusExpired; 123 | 124 | @Override 125 | public String toString() { 126 | return loginStatusExpired; 127 | } 128 | } 129 | } 130 | 131 | class UserPasswordNoCorrect implements ICodingNetOpenAPICodeMsg { 132 | int code; 133 | UserPasswordNoCorrectMsg msg; 134 | 135 | @Override 136 | public String getMessage() { 137 | return msg.toString(); 138 | } 139 | } 140 | 141 | class UserPasswordNoCorrectMsg { 142 | String password; 143 | 144 | @Override 145 | public String toString() { 146 | return password; 147 | } 148 | } 149 | 150 | 151 | class NeedVerificationCode implements ICodingNetOpenAPICodeMsg { 152 | int code; 153 | NeedVerificationCodeMsg msg; 154 | 155 | @Override 156 | public String getMessage() { 157 | return "登陆次数已超过最大上限,请稍后再试."; 158 | } 159 | } 160 | 161 | class NeedVerificationCodeMsg { 162 | @SerializedName("j_captcha") 163 | String captcha; 164 | 165 | @Override 166 | public String toString() { 167 | return captcha; 168 | } 169 | } 170 | 171 | 172 | /** 173 | * 用户不存在 174 | */ 175 | class NoExistUser implements ICodingNetOpenAPICodeMsg { 176 | int code; 177 | NoExistUser msg; 178 | 179 | @Override 180 | public String getMessage() { 181 | return msg.toString(); 182 | } 183 | 184 | } 185 | 186 | class NoExistUserMsg { 187 | String account; 188 | 189 | @Override 190 | public String toString() { 191 | return account; 192 | } 193 | } 194 | 195 | /** 196 | * 未登陆 197 | */ 198 | class NoLogin implements ICodingNetOpenAPICodeMsg { 199 | int code; 200 | NoLoginMsg msg; 201 | 202 | @Override 203 | public String getMessage() { 204 | return msg.toString(); 205 | } 206 | } 207 | 208 | class NoLoginMsg { 209 | @SerializedName("user_not_login") 210 | String userNotLogin; 211 | 212 | @Override 213 | public String toString() { 214 | return userNotLogin; 215 | } 216 | } 217 | 218 | 219 | } 220 | -------------------------------------------------------------------------------- /src/org/coding/git/util/CodingNetUrlUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.util; 17 | 18 | import com.intellij.openapi.util.text.StringUtil; 19 | import org.coding.git.api.CodingNetApiUtil; 20 | import org.jetbrains.annotations.NotNull; 21 | import org.jetbrains.annotations.Nullable; 22 | import org.coding.git.api.CodingNetFullPath; 23 | 24 | /** 25 | * @author robin 26 | */ 27 | public class CodingNetUrlUtil { 28 | 29 | /** 30 | * 去除协议前缀 31 | * @param url 32 | * @return 33 | */ 34 | @NotNull 35 | public static String removeProtocolPrefix(String url) { 36 | int index = url.indexOf('@'); 37 | if (index != -1) { 38 | return url.substring(index + 1).replace(':', '/'); 39 | } 40 | index = url.indexOf("://"); 41 | if (index != -1) { 42 | return url.substring(index + 3); 43 | } 44 | return url; 45 | } 46 | 47 | /** 48 | * 去除结尾斜杠 49 | * @param s 50 | * @return 51 | */ 52 | @NotNull 53 | public static String removeTrailingSlash(@NotNull String s) { 54 | if (s.endsWith("/")) { 55 | return s.substring(0, s.length() - 1); 56 | } 57 | return s; 58 | } 59 | 60 | @NotNull 61 | public static String getApiUrl(@NotNull String urlFromSettings) { 62 | return getApiProtocolFromUrl(urlFromSettings) + getCodingOpenApiUrlDomainNameWithoutProtocol(urlFromSettings); 63 | } 64 | 65 | @NotNull 66 | public static String getApiProtocol() { 67 | return getApiProtocolFromUrl(CodingNetSettings.getInstance().getHost()); 68 | } 69 | 70 | @NotNull 71 | public static String getApiProtocolFromUrl(@NotNull String urlFromSettings) { 72 | if (StringUtil.startsWithIgnoreCase(urlFromSettings.trim(), "http://")) return "http://"; 73 | return "https://"; 74 | } 75 | 76 | @NotNull 77 | public static String getApiUrl() { 78 | return getApiUrl(CodingNetSettings.getInstance().getHost()); 79 | } 80 | 81 | @NotNull 82 | public static String getCodingHost() { 83 | return getApiProtocol() + getGitHostWithoutProtocol(); 84 | } 85 | 86 | @NotNull 87 | public static String getHostFromUrl(@NotNull String url) { 88 | String path = removeProtocolPrefix(url).replace(':', '/'); 89 | int index = path.indexOf('/'); 90 | if (index == -1) { 91 | return path; 92 | } 93 | else { 94 | return path.substring(0, index); 95 | } 96 | } 97 | 98 | @NotNull 99 | public static String getGitHostWithoutProtocol() { 100 | return removeTrailingSlash(removeProtocolPrefix(CodingNetSettings.getInstance().getHost())); 101 | } 102 | 103 | /** 104 | * 根据Coding openAPI请求域名为https://coding.net 105 | * 如获取用户下项目列表为:https://coding.net/api/user/projects 106 | * @param urlFromSettings 107 | * @return 108 | */ 109 | @NotNull 110 | public static String getCodingOpenApiUrlDomainNameWithoutProtocol(@NotNull String urlFromSettings) { 111 | String url = removeTrailingSlash(removeProtocolPrefix(urlFromSettings.toLowerCase())); 112 | if (url.equals(CodingNetApiUtil.DEFAULT_CODING_HOST)) { 113 | return url; 114 | } 115 | return null; 116 | } 117 | 118 | public static boolean isCodingNetUrl(@NotNull String url) { 119 | return isCodingNetUrl(url, CodingNetSettings.getInstance().getHost()); 120 | } 121 | 122 | public static boolean isCodingNetUrl(@NotNull String url, @NotNull String host) { 123 | host = getHostFromUrl(host); 124 | url = removeProtocolPrefix(url); 125 | if (StringUtil.startsWithIgnoreCase(url, host)) { 126 | if (url.length() > host.length() && ":/".indexOf(url.charAt(host.length())) == -1) { 127 | return false; 128 | } 129 | return true; 130 | } 131 | return false; 132 | } 133 | 134 | @Nullable 135 | public static CodingNetFullPath getUserAndRepositoryFromRemoteUrl(@NotNull String remoteUrl) { 136 | remoteUrl = removeProtocolPrefix(removeEndingDotGit(remoteUrl)); 137 | int index1 = remoteUrl.lastIndexOf('/'); 138 | if (index1 == -1) { 139 | return null; 140 | } 141 | String url = remoteUrl.substring(0, index1); 142 | int index2 = Math.max(url.lastIndexOf('/'), url.lastIndexOf(':')); 143 | if (index2 == -1) { 144 | return null; 145 | } 146 | final String username = remoteUrl.substring(index2 + 1, index1); 147 | final String reponame = remoteUrl.substring(index1 + 1); 148 | if (username.isEmpty() || reponame.isEmpty()) { 149 | return null; 150 | } 151 | return new CodingNetFullPath(username, reponame); 152 | } 153 | 154 | @Nullable 155 | public static String makeCodingNetRepoUrlFromRemoteUrl(@NotNull String remoteUrl) { 156 | return makeCodingNetRepoUrlFromRemoteUrl(remoteUrl, getCodingHost()); 157 | } 158 | 159 | @Nullable 160 | public static String makeCodingNetRepoUrlFromRemoteUrl(@NotNull String remoteUrl, @NotNull String host) { 161 | CodingNetFullPath repo = getUserAndRepositoryFromRemoteUrl(remoteUrl); 162 | if (repo == null) { 163 | return null; 164 | } 165 | return host + '/' + repo.getUser() + '/' + repo.getRepository(); 166 | } 167 | 168 | @NotNull 169 | private static String removeEndingDotGit(@NotNull String url) { 170 | url = removeTrailingSlash(url); 171 | final String DOT_GIT = ".git"; 172 | if (url.endsWith(DOT_GIT)) { 173 | return url.substring(0, url.length() - DOT_GIT.length()); 174 | } 175 | return url; 176 | } 177 | 178 | @NotNull 179 | public static String getCloneUrl(@NotNull CodingNetFullPath path) { 180 | return getCloneUrl(path.getUser(), path.getRepository()); 181 | } 182 | 183 | @NotNull 184 | public static String getCloneUrl(@NotNull String user, @NotNull String repo) { 185 | if (CodingNetSettings.getInstance().isCloneGitUsingSsh()) { 186 | return "git@" + getGitHostWithoutProtocol() + ":" + user + "/" + repo + ".git"; 187 | } 188 | else { 189 | return getApiProtocol() + getGitHostWithoutProtocol() + "/" + user + "/" + repo + ".git"; 190 | } 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /src/org/coding/git/ui/CodingNetLoginPanel.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 | -------------------------------------------------------------------------------- /src/org/coding/git/util/CodingNetAuthData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.util; 17 | 18 | import com.intellij.openapi.util.text.StringUtil; 19 | import org.coding.git.api.CodingNetApiUtil; 20 | import org.jetbrains.annotations.NotNull; 21 | import org.jetbrains.annotations.Nullable; 22 | 23 | import java.util.UUID; 24 | 25 | /** 26 | * @author robin 27 | */ 28 | public class CodingNetAuthData { 29 | public enum AuthType {BASIC, TOKEN, ANONYMOUS} 30 | 31 | @NotNull 32 | private final AuthType myAuthType; 33 | @NotNull 34 | private final String myHost; 35 | @Nullable 36 | private final BasicAuth myBasicAuth; 37 | @Nullable 38 | private final TokenAuth myTokenAuth; 39 | private final boolean myUseProxy; 40 | 41 | private CodingNetAuthData(@NotNull AuthType authType, 42 | @NotNull String host, 43 | @Nullable BasicAuth basicAuth, 44 | @Nullable TokenAuth tokenAuth, 45 | boolean useProxy) { 46 | myAuthType = authType; 47 | myHost = host; 48 | myBasicAuth = basicAuth; 49 | myTokenAuth = tokenAuth; 50 | myUseProxy = useProxy; 51 | } 52 | 53 | public static CodingNetAuthData createFromSettings() { 54 | return CodingNetSettings.getInstance().getAuthData(); 55 | } 56 | 57 | public static CodingNetAuthData createAnonymous() { 58 | return createAnonymous(CodingNetApiUtil.DEFAULT_CODING_HOST); 59 | } 60 | 61 | public static CodingNetAuthData createAnonymous(@NotNull String host) { 62 | return new CodingNetAuthData(AuthType.ANONYMOUS, host, null, null, true); 63 | } 64 | 65 | public static CodingNetAuthData createBasicAuth(@NotNull String host, @NotNull String login, @NotNull String password) { 66 | return new CodingNetAuthData(AuthType.BASIC, host, new BasicAuth(login, password), null, true); 67 | } 68 | 69 | /** 70 | * 两步认证对象构建 71 | * 72 | * @param host 73 | * @param login 74 | * @param password 75 | * @param code 76 | * @return 77 | */ 78 | public static CodingNetAuthData createBasicAuthTF(@NotNull String host, 79 | @NotNull String login, 80 | @NotNull String password, 81 | @NotNull String sid, 82 | @NotNull String code) { 83 | return new CodingNetAuthData(AuthType.BASIC, host, new BasicAuth(login, password, sid, code), null, true); 84 | } 85 | 86 | public static CodingNetAuthData createTokenAuth(@NotNull String host, @NotNull String token) { 87 | return new CodingNetAuthData(AuthType.TOKEN, host, null, new TokenAuth(token), true); 88 | } 89 | 90 | public static CodingNetAuthData createTokenAuth(@NotNull String host, @NotNull String token, boolean useProxy) { 91 | return new CodingNetAuthData(AuthType.TOKEN, host, null, new TokenAuth(token), useProxy); 92 | } 93 | 94 | @NotNull 95 | public AuthType getAuthType() { 96 | return myAuthType; 97 | } 98 | 99 | @NotNull 100 | public String getHost() { 101 | return myHost; 102 | } 103 | 104 | @Nullable 105 | public BasicAuth getBasicAuth() { 106 | return myBasicAuth; 107 | } 108 | 109 | @Nullable 110 | public TokenAuth getTokenAuth() { 111 | return myTokenAuth; 112 | } 113 | 114 | public boolean isUseProxy() { 115 | return myUseProxy; 116 | } 117 | 118 | @NotNull 119 | public CodingNetAuthData copyWithTwoFactorCode(@NotNull String code) { 120 | if (myBasicAuth == null) { 121 | throw new IllegalStateException("Two factor authentication can be used only with Login/Password"); 122 | } 123 | 124 | return createBasicAuthTF(getHost(), myBasicAuth.getLogin(), myBasicAuth.getPassword(), myBasicAuth.getSid(), code); 125 | } 126 | 127 | /** 128 | * 用户名密码基本认证对象 129 | */ 130 | public static class BasicAuth { 131 | @NotNull 132 | private final String myLogin; 133 | @NotNull 134 | private final String myPassword; 135 | @Nullable 136 | private String mySid; 137 | @Nullable 138 | private String myAuthCode; 139 | 140 | 141 | private BasicAuth(@NotNull String login, @NotNull String password) { 142 | this(login, password, null); 143 | } 144 | 145 | /** 146 | * @param login 147 | * @param password 148 | * @param sid 149 | */ 150 | private BasicAuth(@NotNull String login, @NotNull String password, @Nullable String sid) { 151 | myLogin = login; 152 | myPassword = password; 153 | if (sid == null) { 154 | sid= UUID.randomUUID().toString(); 155 | } 156 | mySid = sid; 157 | } 158 | 159 | private BasicAuth(@NotNull String login, @NotNull String password, @Nullable String sid, @Nullable String authCode) { 160 | this(login, password, sid); 161 | myAuthCode = authCode; 162 | } 163 | 164 | 165 | @NotNull 166 | public String getLogin() { 167 | return myLogin; 168 | } 169 | 170 | @NotNull 171 | public String getPassword() { 172 | return myPassword; 173 | } 174 | 175 | @Nullable 176 | public String getSid() { 177 | return mySid; 178 | } 179 | 180 | public void setSid(@Nullable String sid) { 181 | this.mySid = sid; 182 | } 183 | 184 | @Nullable 185 | public String getAuthCode() { 186 | return myAuthCode; 187 | } 188 | 189 | public void setAuthCode(@Nullable String authCode) { 190 | this.myAuthCode = myAuthCode; 191 | } 192 | } 193 | 194 | 195 | /** 196 | * Token认证 197 | */ 198 | public static class TokenAuth { 199 | @NotNull 200 | private final String myToken; 201 | 202 | private TokenAuth(@NotNull String token) { 203 | myToken = StringUtil.trim(token); 204 | } 205 | 206 | @NotNull 207 | public String getToken() { 208 | return myToken; 209 | } 210 | } 211 | } 212 | -------------------------------------------------------------------------------- /src/org/coding/git/util/CodingNetNotifications.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.util; 17 | 18 | import com.intellij.notification.NotificationListener; 19 | import com.intellij.openapi.diagnostic.Logger; 20 | import com.intellij.openapi.progress.ProcessCanceledException; 21 | import com.intellij.openapi.project.Project; 22 | import com.intellij.openapi.ui.DialogWrapper; 23 | import com.intellij.openapi.ui.Messages; 24 | import com.intellij.openapi.vcs.VcsNotifier; 25 | import org.jetbrains.annotations.NotNull; 26 | import org.jetbrains.annotations.Nullable; 27 | import org.coding.git.exceptions.CodingNetOperationCanceledException; 28 | 29 | import java.awt.*; 30 | 31 | import static org.coding.git.util.CodingNetUtil.getErrorTextFromException; 32 | 33 | public class CodingNetNotifications { 34 | private static final Logger LOG = CodingNetUtil.LOG; 35 | 36 | private static boolean isOperationCanceled(@NotNull Exception e) { 37 | return e instanceof CodingNetOperationCanceledException || 38 | e instanceof ProcessCanceledException; 39 | } 40 | 41 | public static void showInfo(@NotNull Project project, @NotNull String title, @NotNull String message) { 42 | LOG.info(title + "; " + message); 43 | VcsNotifier.getInstance(project).notifyImportantInfo(title, message); 44 | } 45 | 46 | public static void showWarning(@NotNull Project project, @NotNull String title, @NotNull String message) { 47 | LOG.info(title + "; " + message); 48 | VcsNotifier.getInstance(project).notifyImportantWarning(title, message); 49 | } 50 | 51 | public static void showWarning(@NotNull Project project, @NotNull String title, @NotNull Exception e) { 52 | LOG.info(title + "; ", e); 53 | if (isOperationCanceled(e)) return; 54 | VcsNotifier.getInstance(project).notifyImportantWarning(title, getErrorTextFromException(e)); 55 | } 56 | 57 | public static void showError(@NotNull Project project, @NotNull String title, @NotNull String message) { 58 | LOG.info(title + "; " + message); 59 | VcsNotifier.getInstance(project).notifyError(title, message); 60 | } 61 | 62 | public static void showError(@NotNull Project project, @NotNull String title, @NotNull String message, @NotNull String logDetails) { 63 | LOG.warn(title + "; " + message + "; " + logDetails); 64 | VcsNotifier.getInstance(project).notifyError(title, message); 65 | } 66 | 67 | public static void showError(@NotNull Project project, @NotNull String title, @NotNull Exception e) { 68 | LOG.warn(title + "; ", e); 69 | if (isOperationCanceled(e)) return; 70 | VcsNotifier.getInstance(project).notifyError(title, getErrorTextFromException(e)); 71 | } 72 | 73 | public static void showInfoURL(@NotNull Project project, @NotNull String title, @NotNull String message, @NotNull String url) { 74 | LOG.info(title + "; " + message + "; " + url); 75 | VcsNotifier.getInstance(project) 76 | .notifyImportantInfo(title, "" + message + "", NotificationListener.URL_OPENING_LISTENER); 77 | } 78 | 79 | public static void showWarningURL(@NotNull Project project, 80 | @NotNull String title, 81 | @NotNull String prefix, 82 | @NotNull String highlight, 83 | @NotNull String postfix, 84 | @NotNull String url) { 85 | LOG.info(title + "; " + prefix + highlight + postfix + "; " + url); 86 | VcsNotifier.getInstance(project).notifyImportantWarning(title, prefix + "" + highlight + "" + postfix, 87 | NotificationListener.URL_OPENING_LISTENER); 88 | } 89 | 90 | public static void showErrorURL(@NotNull Project project, 91 | @NotNull String title, 92 | @NotNull String prefix, 93 | @NotNull String highlight, 94 | @NotNull String postfix, 95 | @NotNull String url) { 96 | LOG.info(title + "; " + prefix + highlight + postfix + "; " + url); 97 | VcsNotifier.getInstance(project).notifyError(title, prefix + "" + highlight + "" + postfix, 98 | NotificationListener.URL_OPENING_LISTENER); 99 | } 100 | 101 | public static void showInfoDialog(@Nullable Project project, @NotNull String title, @NotNull String message) { 102 | LOG.info(title + "; " + message); 103 | Messages.showInfoMessage(project, message, title); 104 | } 105 | 106 | public static void showInfoDialog(@NotNull Component component, @NotNull String title, @NotNull String message) { 107 | LOG.info(title + "; " + message); 108 | Messages.showInfoMessage(component, message, title); 109 | } 110 | 111 | public static void showWarningDialog(@Nullable Project project, @NotNull String title, @NotNull String message) { 112 | LOG.info(title + "; " + message); 113 | Messages.showWarningDialog(project, message, title); 114 | } 115 | 116 | public static void showWarningDialog(@NotNull Component component, @NotNull String title, @NotNull String message) { 117 | LOG.info(title + "; " + message); 118 | Messages.showWarningDialog(component, message, title); 119 | } 120 | 121 | public static void showErrorDialog(@Nullable Project project, @NotNull String title, @NotNull String message) { 122 | LOG.info(title + "; " + message); 123 | Messages.showErrorDialog(project, message, title); 124 | } 125 | 126 | public static void showErrorDialog(@Nullable Project project, @NotNull String title, @NotNull Exception e) { 127 | LOG.warn(title, e); 128 | if (isOperationCanceled(e)) return; 129 | Messages.showErrorDialog(project, getErrorTextFromException(e), title); 130 | } 131 | 132 | public static void showErrorDialog(@NotNull Component component, @NotNull String title, @NotNull Exception e) { 133 | LOG.info(title, e); 134 | if (isOperationCanceled(e)) return; 135 | Messages.showErrorDialog(component, getErrorTextFromException(e), title); 136 | } 137 | 138 | public static void showErrorDialog(@NotNull Component component, @NotNull String title, @NotNull String prefix, @NotNull Exception e) { 139 | LOG.info(title, e); 140 | if (isOperationCanceled(e)) return; 141 | Messages.showErrorDialog(component, prefix + getErrorTextFromException(e), title); 142 | } 143 | 144 | @Messages.YesNoResult 145 | public static boolean showYesNoDialog(@Nullable Project project, @NotNull String title, @NotNull String message) { 146 | return Messages.YES == Messages.showYesNoDialog(project, message, title, Messages.getQuestionIcon()); 147 | } 148 | 149 | @Messages.YesNoResult 150 | public static boolean showYesNoDialog(@Nullable Project project, 151 | @NotNull String title, 152 | @NotNull String message, 153 | @NotNull DialogWrapper.DoNotAskOption doNotAskOption) { 154 | return Messages.YES == Messages.showYesNoDialog(project, message, title, Messages.getQuestionIcon(), doNotAskOption); 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /src/org/coding/git/tasks/CodingNetRepositoryEditor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.tasks; 17 | 18 | import com.intellij.openapi.project.Project; 19 | import com.intellij.openapi.util.text.StringUtil; 20 | import com.intellij.tasks.config.BaseRepositoryEditor; 21 | import com.intellij.ui.DocumentAdapter; 22 | import com.intellij.ui.components.JBCheckBox; 23 | import com.intellij.ui.components.JBLabel; 24 | import com.intellij.ui.components.JBTextField; 25 | import com.intellij.util.Consumer; 26 | import com.intellij.util.ui.FormBuilder; 27 | import com.intellij.util.ui.GridBag; 28 | import org.coding.git.api.CodingNetApiUtil; 29 | import org.coding.git.util.CodingNetNotifications; 30 | import org.coding.git.util.CodingNetUtil; 31 | import org.jetbrains.annotations.NotNull; 32 | import org.jetbrains.annotations.Nullable; 33 | import org.coding.git.util.CodingNetAuthDataHolder; 34 | 35 | import javax.swing.*; 36 | import javax.swing.event.DocumentEvent; 37 | import javax.swing.event.DocumentListener; 38 | import java.awt.*; 39 | import java.io.IOException; 40 | 41 | 42 | public class CodingNetRepositoryEditor extends BaseRepositoryEditor { 43 | private MyTextField myRepoAuthor; 44 | private MyTextField myRepoName; 45 | private MyTextField myToken; 46 | private JBCheckBox myShowNotAssignedIssues; 47 | private JButton myTokenButton; 48 | private JBLabel myHostLabel; 49 | private JBLabel myRepositoryLabel; 50 | private JBLabel myTokenLabel; 51 | 52 | public CodingNetRepositoryEditor(final Project project, final CodingNetRepository repository, Consumer changeListener) { 53 | super(project, repository, changeListener); 54 | myUrlLabel.setVisible(false); 55 | myUsernameLabel.setVisible(false); 56 | myUserNameText.setVisible(false); 57 | myPasswordLabel.setVisible(false); 58 | myPasswordText.setVisible(false); 59 | myUseHttpAuthenticationCheckBox.setVisible(false); 60 | 61 | myRepoAuthor.setText(repository.getRepoAuthor()); 62 | myRepoName.setText(repository.getRepoName()); 63 | myToken.setText(repository.getToken()); 64 | myToken.setText(repository.getToken()); 65 | myShowNotAssignedIssues.setSelected(!repository.isAssignedIssuesOnly()); 66 | 67 | DocumentListener buttonUpdater = new DocumentAdapter() { 68 | @Override 69 | protected void textChanged(DocumentEvent e) { 70 | updateTokenButton(); 71 | } 72 | }; 73 | 74 | myURLText.getDocument().addDocumentListener(buttonUpdater); 75 | myRepoAuthor.getDocument().addDocumentListener(buttonUpdater); 76 | myRepoName.getDocument().addDocumentListener(buttonUpdater); 77 | } 78 | 79 | @Nullable 80 | @Override 81 | protected JComponent createCustomPanel() { 82 | myHostLabel = new JBLabel("Host:", SwingConstants.RIGHT); 83 | 84 | JPanel myHostPanel = new JPanel(new BorderLayout(5, 0)); 85 | myHostPanel.add(myURLText, BorderLayout.CENTER); 86 | myHostPanel.add(myShareUrlCheckBox, BorderLayout.EAST); 87 | 88 | myRepositoryLabel = new JBLabel("Repository:", SwingConstants.RIGHT); 89 | myRepoAuthor = new MyTextField("Repository Owner"); 90 | myRepoName = new MyTextField("Repository Name"); 91 | myRepoAuthor.setPreferredSize("SomelongNickname"); 92 | myRepoName.setPreferredSize("SomelongReponame-with-suffixes"); 93 | 94 | JPanel myRepoPanel = new JPanel(new GridBagLayout()); 95 | GridBag bag = new GridBag().setDefaultWeightX(1).setDefaultFill(GridBagConstraints.HORIZONTAL); 96 | myRepoPanel.add(myRepoAuthor, bag.nextLine().next()); 97 | myRepoPanel.add(new JLabel("/"), bag.next().fillCellNone().insets(0, 5, 0, 5).weightx(0)); 98 | myRepoPanel.add(myRepoName, bag.next()); 99 | 100 | myTokenLabel = new JBLabel("API Token:", SwingConstants.RIGHT); 101 | myToken = new MyTextField("OAuth2 token"); 102 | myTokenButton = new JButton("Create API token"); 103 | myTokenButton.addActionListener(e -> { 104 | generateToken(); 105 | doApply(); 106 | }); 107 | 108 | JPanel myTokenPanel = new JPanel(); 109 | myTokenPanel.setLayout(new BorderLayout(5, 5)); 110 | myTokenPanel.add(myToken, BorderLayout.CENTER); 111 | myTokenPanel.add(myTokenButton, BorderLayout.EAST); 112 | 113 | myShowNotAssignedIssues = new JBCheckBox("Include issues not assigned to me"); 114 | 115 | installListener(myRepoAuthor); 116 | installListener(myRepoName); 117 | installListener(myToken); 118 | installListener(myShowNotAssignedIssues); 119 | 120 | return FormBuilder.createFormBuilder() 121 | .setAlignLabelOnRight(true) 122 | .addLabeledComponent(myHostLabel, myHostPanel) 123 | .addLabeledComponent(myRepositoryLabel, myRepoPanel) 124 | .addLabeledComponent(myTokenLabel, myTokenPanel) 125 | .addComponentToRightColumn(myShowNotAssignedIssues) 126 | .getPanel(); 127 | } 128 | 129 | @Override 130 | public void apply() { 131 | myRepository.setRepoName(getRepoName()); 132 | myRepository.setRepoAuthor(getRepoAuthor()); 133 | myRepository.setToken(getToken()); 134 | myRepository.setAssignedIssuesOnly(isAssignedIssuesOnly()); 135 | super.apply(); 136 | } 137 | 138 | private void generateToken() { 139 | try { 140 | String token = CodingNetUtil.computeValueInModalIO(myProject, "Access to GitHub", indicator -> 141 | CodingNetUtil.runTaskWithBasicAuthForHost(myProject, CodingNetAuthDataHolder.createFromSettings(), indicator, getHost(), connection -> 142 | CodingNetApiUtil.getTasksToken(connection, getRepoAuthor(), getRepoName(), "IntelliJ tasks plugin") 143 | )); 144 | myToken.setText(token); 145 | } 146 | catch (IOException e) { 147 | CodingNetNotifications.showErrorDialog(myProject, "Can't Get Access Token", e); 148 | } 149 | } 150 | 151 | @Override 152 | public void setAnchor(@Nullable final JComponent anchor) { 153 | super.setAnchor(anchor); 154 | myHostLabel.setAnchor(anchor); 155 | myRepositoryLabel.setAnchor(anchor); 156 | myTokenLabel.setAnchor(anchor); 157 | } 158 | 159 | private void updateTokenButton() { 160 | if (StringUtil.isEmptyOrSpaces(getHost()) || 161 | StringUtil.isEmptyOrSpaces(getRepoAuthor()) || 162 | StringUtil.isEmptyOrSpaces(getRepoName())) { 163 | myTokenButton.setEnabled(false); 164 | } 165 | else { 166 | myTokenButton.setEnabled(true); 167 | } 168 | } 169 | 170 | @NotNull 171 | private String getHost() { 172 | return myURLText.getText().trim(); 173 | } 174 | 175 | @NotNull 176 | private String getRepoAuthor() { 177 | return myRepoAuthor.getText().trim(); 178 | } 179 | 180 | @NotNull 181 | private String getRepoName() { 182 | return myRepoName.getText().trim(); 183 | } 184 | 185 | @NotNull 186 | private String getToken() { 187 | return myToken.getText().trim(); 188 | } 189 | 190 | private boolean isAssignedIssuesOnly() { 191 | return !myShowNotAssignedIssues.isSelected(); 192 | } 193 | 194 | public static class MyTextField extends JBTextField { 195 | private int myWidth = -1; 196 | 197 | public MyTextField(@NotNull String hintCaption) { 198 | getEmptyText().setText(hintCaption); 199 | } 200 | 201 | public void setPreferredSize(@NotNull String sampleSizeString) { 202 | myWidth = getFontMetrics(getFont()).stringWidth(sampleSizeString); 203 | } 204 | 205 | @Override 206 | public Dimension getPreferredSize() { 207 | Dimension size = super.getPreferredSize(); 208 | if (myWidth != -1) { 209 | size.width = myWidth; 210 | } 211 | return size; 212 | } 213 | } 214 | } 215 | -------------------------------------------------------------------------------- /src/org/coding/git/ui/CodingNetLoginPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.ui; 17 | 18 | import com.intellij.ide.BrowserUtil; 19 | import com.intellij.openapi.ui.ComboBox; 20 | import com.intellij.ui.DocumentAdapter; 21 | import com.intellij.ui.HyperlinkAdapter; 22 | import com.intellij.util.containers.ContainerUtil; 23 | import com.intellij.util.ui.JBUI; 24 | import com.intellij.util.ui.UIUtil; 25 | import com.intellij.util.ui.table.ComponentsListFocusTraversalPolicy; 26 | import org.coding.git.util.CodingNetUtil; 27 | import org.jetbrains.annotations.NotNull; 28 | import org.jetbrains.annotations.Nullable; 29 | import org.coding.git.util.CodingNetAuthData; 30 | 31 | import javax.swing.*; 32 | import javax.swing.event.DocumentEvent; 33 | import javax.swing.event.DocumentListener; 34 | import javax.swing.event.HyperlinkEvent; 35 | import java.awt.*; 36 | import java.awt.event.ItemEvent; 37 | import java.util.ArrayList; 38 | import java.util.List; 39 | 40 | 41 | public class CodingNetLoginPanel { 42 | private JPanel myPane; 43 | private JTextField myHostTextField; 44 | private JTextField myLoginTextField; 45 | private JPasswordField myPasswordField; 46 | private JTextPane mySignupTextField; 47 | private JCheckBox mySavePasswordCheckBox; 48 | private ComboBox myAuthTypeComboBox; 49 | private JLabel myPasswordLabel; 50 | private JLabel myLoginLabel; 51 | private JTextField myVerificationCodeTextField; 52 | private JPanel myVerificationCodePanel; 53 | private JLabel myVerificationLabel; 54 | 55 | private final static String AUTH_PASSWORD = "Password"; 56 | //private final static String AUTH_TOKEN = "Token"; 57 | 58 | public CodingNetLoginPanel(final CodingNetLoginDialog dialog) { 59 | DocumentListener listener = new DocumentAdapter() { 60 | @Override 61 | protected void textChanged(DocumentEvent e) { 62 | dialog.clearErrors(); 63 | } 64 | }; 65 | myLoginTextField.getDocument().addDocumentListener(listener); 66 | myPasswordField.getDocument().addDocumentListener(listener); 67 | mySignupTextField.setText("Do not have an account at coding.net? Sign up."); 68 | mySignupTextField.setMargin(JBUI.insetsTop(5)); 69 | mySignupTextField.addHyperlinkListener(new HyperlinkAdapter() { 70 | @Override 71 | protected void hyperlinkActivated(final HyperlinkEvent e) { 72 | BrowserUtil.browse(e.getURL()); 73 | } 74 | }); 75 | mySignupTextField.setBackground(UIUtil.TRANSPARENT_COLOR); 76 | mySignupTextField.setCursor(new Cursor(Cursor.HAND_CURSOR)); 77 | 78 | myAuthTypeComboBox.addItem(AUTH_PASSWORD); 79 | //myAuthTypeComboBox.addItem(AUTH_TOKEN); 80 | 81 | myAuthTypeComboBox.addItemListener(e -> { 82 | if (e.getStateChange() == ItemEvent.SELECTED) { 83 | String item = e.getItem().toString(); 84 | if (AUTH_PASSWORD.equals(item)) { 85 | myPasswordLabel.setText("Password:"); 86 | mySavePasswordCheckBox.setText("Save password"); 87 | myLoginLabel.setVisible(true); 88 | myLoginTextField.setVisible(true); 89 | } 90 | // else if (AUTH_TOKEN.equals(item)) { 91 | // myPasswordLabel.setText("Token:"); 92 | // mySavePasswordCheckBox.setText("Save token"); 93 | // myLoginLabel.setVisible(false); 94 | // myLoginTextField.setVisible(false); 95 | // } 96 | if (dialog.isShowing()) { 97 | dialog.pack(); 98 | } 99 | } 100 | }); 101 | 102 | List order = new ArrayList(); 103 | order.add(myHostTextField); 104 | order.add(myAuthTypeComboBox); 105 | order.add(mySavePasswordCheckBox); 106 | order.add(myLoginTextField); 107 | order.add(myPasswordField); 108 | myPane.setFocusTraversalPolicyProvider(true); 109 | myPane.setFocusTraversalPolicy(new MyFocusTraversalPolicy(order)); 110 | 111 | myVerificationLabel.setVisible(false); 112 | myVerificationCodePanel.setVisible(false); 113 | myVerificationCodeTextField.setVisible(false); 114 | } 115 | 116 | public JComponent getPanel() { 117 | return myPane; 118 | } 119 | 120 | public void setHost(@NotNull String host) { 121 | myHostTextField.setText(host); 122 | } 123 | 124 | public void setLogin(@Nullable String login) { 125 | myLoginTextField.setText(login); 126 | } 127 | 128 | public void setAuthType(@NotNull CodingNetAuthData.AuthType type) { 129 | switch (type) { 130 | case BASIC: 131 | myAuthTypeComboBox.setSelectedItem(AUTH_PASSWORD); 132 | break; 133 | // case TOKEN: 134 | // myAuthTypeComboBox.setSelectedItem(AUTH_TOKEN); 135 | // break; 136 | case ANONYMOUS: 137 | myAuthTypeComboBox.setSelectedItem(AUTH_PASSWORD); 138 | } 139 | } 140 | 141 | public void lockAuthType(@NotNull CodingNetAuthData.AuthType type) { 142 | setAuthType(type); 143 | myAuthTypeComboBox.setEnabled(false); 144 | } 145 | 146 | public void lockHost(@NotNull String host) { 147 | setHost(host); 148 | myHostTextField.setEnabled(false); 149 | } 150 | 151 | public void setSavePasswordSelected(boolean savePassword) { 152 | mySavePasswordCheckBox.setSelected(savePassword); 153 | } 154 | 155 | public void setSavePasswordVisibleEnabled(boolean visible) { 156 | mySavePasswordCheckBox.setVisible(visible); 157 | mySavePasswordCheckBox.setEnabled(visible); 158 | } 159 | 160 | @NotNull 161 | public String getHost() { 162 | return myHostTextField.getText().trim(); 163 | } 164 | 165 | @NotNull 166 | public String getLogin() { 167 | return myLoginTextField.getText().trim(); 168 | } 169 | 170 | @NotNull 171 | private String getPassword() { 172 | return String.valueOf(myPasswordField.getPassword()); 173 | } 174 | 175 | public boolean isSavePasswordSelected() { 176 | return mySavePasswordCheckBox.isSelected(); 177 | } 178 | 179 | public JComponent getPreferableFocusComponent() { 180 | return myLoginTextField.isVisible() ? myLoginTextField : myPasswordField; 181 | } 182 | 183 | @NotNull 184 | public CodingNetAuthData getAuthData() { 185 | Object selected = myAuthTypeComboBox.getSelectedItem(); 186 | if (AUTH_PASSWORD.equals(selected)) 187 | return CodingNetAuthData.createBasicAuth(getHost(), getLogin(), getPassword()); 188 | // if (AUTH_TOKEN.equals(selected)) return CodingNetAuthData.createTokenAuth(getHost(), getPassword()); 189 | // CodingNetUtil.LOG.error("CodingNetLoginPanel illegal selection: anonymous AuthData created", selected.toString()); 190 | return CodingNetAuthData.createAnonymous(getHost()); 191 | } 192 | 193 | private static class MyFocusTraversalPolicy extends ComponentsListFocusTraversalPolicy { 194 | @NotNull 195 | private List myOrder; 196 | 197 | private MyFocusTraversalPolicy(@NotNull List order) { 198 | myOrder = order; 199 | } 200 | 201 | @NotNull 202 | @Override 203 | protected List getOrderedComponents() { 204 | return ContainerUtil.filter(myOrder, component -> component.isVisible() && component.isEnabled()); 205 | } 206 | } 207 | } 208 | 209 | -------------------------------------------------------------------------------- /src/org/coding/git/util/CodingNetSettings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Coding 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.coding.git.util; 17 | 18 | import com.intellij.ide.passwordSafe.PasswordSafe; 19 | import com.intellij.ide.passwordSafe.PasswordSafeException; 20 | import com.intellij.ide.passwordSafe.impl.PasswordSafeImpl; 21 | import com.intellij.openapi.components.PersistentStateComponent; 22 | import com.intellij.openapi.components.ServiceManager; 23 | import com.intellij.openapi.components.State; 24 | import com.intellij.openapi.components.Storage; 25 | import com.intellij.openapi.diagnostic.Logger; 26 | import com.intellij.openapi.util.text.StringUtil; 27 | import com.intellij.util.ThreeState; 28 | import org.coding.git.api.CodingNetApiUtil; 29 | import org.jetbrains.annotations.NotNull; 30 | import org.jetbrains.annotations.Nullable; 31 | 32 | import static com.intellij.credentialStore.ProviderType.*; 33 | import static org.coding.git.util.CodingNetAuthData.AuthType; 34 | 35 | 36 | /** 37 | * @author robin 38 | */ 39 | @State(name = "CodingSettings", storages = @Storage("coding_settings.xml")) 40 | public class CodingNetSettings implements PersistentStateComponent { 41 | private static final Logger LOG = CodingNetUtil.LOG; 42 | private static final String CODINGNET_SETTINGS_PASSWORD_KEY = "CODINGNET_SETTINGS_PASSWORD_KEY"; 43 | 44 | private State myState = new State(); 45 | 46 | public State getState() { 47 | return myState; 48 | } 49 | 50 | public void loadState(State state) { 51 | myState = state; 52 | } 53 | 54 | public static class State { 55 | @Nullable public String LOGIN = null; 56 | @NotNull public String HOST = CodingNetApiUtil.DEFAULT_CODING_HOST; 57 | @NotNull public AuthType AUTH_TYPE = AuthType.ANONYMOUS; 58 | public boolean ANONYMOUS_GIST = false; 59 | public boolean OPEN_IN_BROWSER_GIST = true; 60 | public boolean PRIVATE_GIST = true; 61 | public boolean SAVE_PASSWORD = true; 62 | public int CONNECTION_TIMEOUT = 5000; 63 | public boolean VALID_GIT_AUTH = true; 64 | public ThreeState CREATE_PULL_REQUEST_CREATE_REMOTE = ThreeState.UNSURE; 65 | public boolean CLONE_GIT_USING_SSH = false; 66 | } 67 | 68 | public static CodingNetSettings getInstance() { 69 | return ServiceManager.getService(CodingNetSettings.class); 70 | } 71 | 72 | public int getConnectionTimeout() { 73 | return myState.CONNECTION_TIMEOUT; 74 | } 75 | 76 | public void setConnectionTimeout(int timeout) { 77 | myState.CONNECTION_TIMEOUT = timeout; 78 | } 79 | 80 | @NotNull 81 | public String getHost() { 82 | return myState.HOST; 83 | } 84 | 85 | @Nullable 86 | public String getLogin() { 87 | return myState.LOGIN; 88 | } 89 | 90 | @NotNull 91 | public AuthType getAuthType() { 92 | return myState.AUTH_TYPE; 93 | } 94 | 95 | public boolean isAuthConfigured() { 96 | return !myState.AUTH_TYPE.equals(AuthType.ANONYMOUS); 97 | } 98 | 99 | private void setHost(@NotNull String host) { 100 | myState.HOST = StringUtil.notNullize(host, CodingNetApiUtil.DEFAULT_CODING_HOST); 101 | } 102 | 103 | private void setLogin(@Nullable String login) { 104 | myState.LOGIN = login; 105 | } 106 | 107 | private void setAuthType(@NotNull AuthType authType) { 108 | myState.AUTH_TYPE = authType; 109 | } 110 | 111 | public boolean isAnonymousGist() { 112 | return myState.ANONYMOUS_GIST; 113 | } 114 | 115 | public boolean isOpenInBrowserGist() { 116 | return myState.OPEN_IN_BROWSER_GIST; 117 | } 118 | 119 | public boolean isPrivateGist() { 120 | return myState.PRIVATE_GIST; 121 | } 122 | 123 | public boolean isSavePassword() { 124 | return myState.SAVE_PASSWORD; 125 | } 126 | 127 | public boolean isValidGitAuth() { 128 | return myState.VALID_GIT_AUTH; 129 | } 130 | 131 | public boolean isSavePasswordMakesSense() { 132 | final PasswordSafeImpl passwordSafe = (PasswordSafeImpl)PasswordSafe.getInstance(); 133 | return passwordSafe.getSettings().getProviderType() == KEEPASS; 134 | } 135 | 136 | public boolean isCloneGitUsingSsh() { 137 | return myState.CLONE_GIT_USING_SSH; 138 | } 139 | 140 | @NotNull 141 | public ThreeState getCreatePullRequestCreateRemote() { 142 | return myState.CREATE_PULL_REQUEST_CREATE_REMOTE; 143 | } 144 | 145 | public void setCreatePullRequestCreateRemote(@NotNull ThreeState value) { 146 | myState.CREATE_PULL_REQUEST_CREATE_REMOTE = value; 147 | } 148 | 149 | public void setAnonymousGist(final boolean anonymousGist) { 150 | myState.ANONYMOUS_GIST = anonymousGist; 151 | } 152 | 153 | public void setPrivateGist(final boolean privateGist) { 154 | myState.PRIVATE_GIST = privateGist; 155 | } 156 | 157 | public void setSavePassword(final boolean savePassword) { 158 | myState.SAVE_PASSWORD = savePassword; 159 | } 160 | 161 | public void setValidGitAuth(final boolean validGitAuth) { 162 | myState.VALID_GIT_AUTH = validGitAuth; 163 | } 164 | 165 | public void setOpenInBrowserGist(final boolean openInBrowserGist) { 166 | myState.OPEN_IN_BROWSER_GIST = openInBrowserGist; 167 | } 168 | 169 | public void setCloneGitUsingSsh(boolean value) { 170 | myState.CLONE_GIT_USING_SSH = value; 171 | } 172 | 173 | @NotNull 174 | private String getPassword() { 175 | String password; 176 | try { 177 | password = PasswordSafe.getInstance().getPassword(null, CodingNetSettings.class, CODINGNET_SETTINGS_PASSWORD_KEY); 178 | } 179 | catch (PasswordSafeException e) { 180 | LOG.info("Couldn't get password for key [" + CODINGNET_SETTINGS_PASSWORD_KEY + "]", e); 181 | password = ""; 182 | } 183 | 184 | return StringUtil.notNullize(password); 185 | } 186 | 187 | private void setPassword(@NotNull String password, boolean rememberPassword) { 188 | try { 189 | if (rememberPassword) { 190 | PasswordSafe.getInstance().storePassword(null, CodingNetSettings.class, CODINGNET_SETTINGS_PASSWORD_KEY, password); 191 | } 192 | else { 193 | final PasswordSafeImpl passwordSafe = (PasswordSafeImpl)PasswordSafe.getInstance(); 194 | if (passwordSafe.getSettings().getProviderType() != DO_NOT_STORE) { 195 | passwordSafe.getMemoryProvider().storePassword(null, CodingNetSettings.class, CODINGNET_SETTINGS_PASSWORD_KEY, password); 196 | } 197 | } 198 | } 199 | catch (PasswordSafeException e) { 200 | LOG.info("Couldn't set password for key [" + CODINGNET_SETTINGS_PASSWORD_KEY + "]", e); 201 | } 202 | } 203 | 204 | private static boolean isValidGitAuth(@NotNull CodingNetAuthData auth) { 205 | switch (auth.getAuthType()) { 206 | case BASIC: 207 | assert auth.getBasicAuth() != null; 208 | return auth.getBasicAuth().getSid() == null; 209 | case TOKEN: 210 | return true; 211 | case ANONYMOUS: 212 | return false; 213 | default: 214 | throw new IllegalStateException("CodingNetSettings: setAuthData - wrong AuthType: " + auth.getAuthType()); 215 | } 216 | } 217 | 218 | @NotNull 219 | public CodingNetAuthData getAuthData() { 220 | switch (getAuthType()) { 221 | case BASIC: 222 | //noinspection ConstantConditions 223 | return CodingNetAuthData.createBasicAuth(getHost(), getLogin(), getPassword()); 224 | case TOKEN: 225 | return CodingNetAuthData.createTokenAuth(getHost(), getPassword()); 226 | case ANONYMOUS: 227 | return CodingNetAuthData.createAnonymous(); 228 | default: 229 | throw new IllegalStateException("CodingNetSettings: getAuthData - wrong AuthType: " + getAuthType()); 230 | } 231 | } 232 | 233 | public void setAuthData(@NotNull CodingNetAuthData auth, boolean rememberPassword) { 234 | setValidGitAuth(isValidGitAuth(auth)); 235 | 236 | setAuthType(auth.getAuthType()); 237 | setHost(auth.getHost()); 238 | 239 | switch (auth.getAuthType()) { 240 | case BASIC: 241 | assert auth.getBasicAuth() != null; 242 | setLogin(auth.getBasicAuth().getLogin()); 243 | setPassword(auth.getBasicAuth().getPassword(), rememberPassword); 244 | break; 245 | case TOKEN: 246 | assert auth.getTokenAuth() != null; 247 | setLogin(null); 248 | setPassword(auth.getTokenAuth().getToken(), rememberPassword); 249 | break; 250 | case ANONYMOUS: 251 | setLogin(null); 252 | setPassword("", rememberPassword); 253 | break; 254 | default: 255 | throw new IllegalStateException("CodingNetSettings: setAuthData - wrong AuthType: " + auth.getAuthType()); 256 | } 257 | } 258 | } -------------------------------------------------------------------------------- /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, and 10 | distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by the copyright 13 | owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all other entities 16 | that control, are controlled by, or are under common control with that entity. 17 | For the purposes of this definition, "control" means (i) the power, direct or 18 | indirect, to cause the direction or management of such entity, whether by 19 | contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the 20 | outstanding shares, or (iii) beneficial ownership of such entity. 21 | 22 | "You" (or "Your") shall mean an individual or Legal Entity exercising 23 | permissions granted by this License. 24 | 25 | "Source" form shall mean the preferred form for making modifications, including 26 | but not limited to software source code, documentation source, and configuration 27 | files. 28 | 29 | "Object" form shall mean any form resulting from mechanical transformation or 30 | translation of a Source form, including but not limited to compiled object code, 31 | generated documentation, and conversions to other media types. 32 | 33 | "Work" shall mean the work of authorship, whether in Source or Object form, made 34 | available under the License, as indicated by a copyright notice that is included 35 | in or attached to the work (an example is provided in the Appendix below). 36 | 37 | "Derivative Works" shall mean any work, whether in Source or Object form, that 38 | is based on (or derived from) the Work and for which the editorial revisions, 39 | annotations, elaborations, or other modifications represent, as a whole, an 40 | original work of authorship. For the purposes of this License, Derivative Works 41 | shall not include works that remain separable from, or merely link (or bind by 42 | name) to the interfaces of, the Work and Derivative Works thereof. 43 | 44 | "Contribution" shall mean any work of authorship, including the original version 45 | of the Work and any modifications or additions to that Work or Derivative Works 46 | thereof, that is intentionally submitted to Licensor for inclusion in the Work 47 | by the copyright owner or by an individual or Legal Entity authorized to submit 48 | on behalf of the copyright owner. For the purposes of this definition, 49 | "submitted" means any form of electronic, verbal, or written communication sent 50 | to the Licensor or its representatives, including but not limited to 51 | communication on electronic mailing lists, source code control systems, and 52 | issue tracking systems that are managed by, or on behalf of, the Licensor for 53 | the purpose of discussing and improving the Work, but excluding communication 54 | that is conspicuously marked or otherwise designated in writing by the copyright 55 | owner as "Not a Contribution." 56 | 57 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf 58 | of whom a Contribution has been received by Licensor and subsequently 59 | incorporated within the Work. 60 | 61 | 2. Grant of Copyright License. 62 | 63 | Subject to the terms and conditions of this License, each Contributor hereby 64 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 65 | irrevocable copyright license to reproduce, prepare Derivative Works of, 66 | publicly display, publicly perform, sublicense, and distribute the Work and such 67 | Derivative Works in Source or Object form. 68 | 69 | 3. Grant of Patent License. 70 | 71 | Subject to the terms and conditions of this License, each Contributor hereby 72 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 73 | irrevocable (except as stated in this section) patent license to make, have 74 | made, use, offer to sell, sell, import, and otherwise transfer the Work, where 75 | such license applies only to those patent claims licensable by such Contributor 76 | that are necessarily infringed by their Contribution(s) alone or by combination 77 | of their Contribution(s) with the Work to which such Contribution(s) was 78 | submitted. If You institute patent litigation against any entity (including a 79 | cross-claim or counterclaim in a lawsuit) alleging that the Work or a 80 | Contribution incorporated within the Work constitutes direct or contributory 81 | patent infringement, then any patent licenses granted to You under this License 82 | for that Work shall terminate as of the date such litigation is filed. 83 | 84 | 4. Redistribution. 85 | 86 | You may reproduce and distribute copies of the Work or Derivative Works thereof 87 | in any medium, with or without modifications, and in Source or Object form, 88 | provided that You meet the following conditions: 89 | 90 | You must give any other recipients of the Work or Derivative Works a copy of 91 | this License; and 92 | You must cause any modified files to carry prominent notices stating that You 93 | changed the files; and 94 | You must retain, in the Source form of any Derivative Works that You distribute, 95 | all copyright, patent, trademark, and attribution notices from the Source form 96 | of the Work, excluding those notices that do not pertain to any part of the 97 | Derivative Works; and 98 | If the Work includes a "NOTICE" text file as part of its distribution, then any 99 | Derivative Works that You distribute must include a readable copy of the 100 | attribution notices contained within such NOTICE file, excluding those notices 101 | that do not pertain to any part of the Derivative Works, in at least one of the 102 | following places: within a NOTICE text file distributed as part of the 103 | Derivative Works; within the Source form or documentation, if provided along 104 | with the Derivative Works; or, within a display generated by the Derivative 105 | Works, if and wherever such third-party notices normally appear. The contents of 106 | the NOTICE file are for informational purposes only and do not modify the 107 | License. You may add Your own attribution notices within Derivative Works that 108 | You distribute, alongside or as an addendum to the NOTICE text from the Work, 109 | provided that such additional attribution notices cannot be construed as 110 | modifying the License. 111 | You may add Your own copyright statement to Your modifications and may provide 112 | additional or different license terms and conditions for use, reproduction, or 113 | distribution of Your modifications, or for any such Derivative Works as a whole, 114 | provided Your use, reproduction, and distribution of the Work otherwise complies 115 | with the conditions stated in this License. 116 | 117 | 5. Submission of Contributions. 118 | 119 | Unless You explicitly state otherwise, any Contribution intentionally submitted 120 | for inclusion in the Work by You to the Licensor shall be under the terms and 121 | conditions of this License, without any additional terms or conditions. 122 | Notwithstanding the above, nothing herein shall supersede or modify the terms of 123 | any separate license agreement you may have executed with Licensor regarding 124 | such Contributions. 125 | 126 | 6. Trademarks. 127 | 128 | This License does not grant permission to use the trade names, trademarks, 129 | service marks, or product names of the Licensor, except as required for 130 | reasonable and customary use in describing the origin of the Work and 131 | reproducing the content of the NOTICE file. 132 | 133 | 7. Disclaimer of Warranty. 134 | 135 | Unless required by applicable law or agreed to in writing, Licensor provides the 136 | Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, 137 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 138 | including, without limitation, any warranties or conditions of TITLE, 139 | NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are 140 | solely responsible for determining the appropriateness of using or 141 | redistributing the Work and assume any risks associated with Your exercise of 142 | permissions under this License. 143 | 144 | 8. Limitation of Liability. 145 | 146 | In no event and under no legal theory, whether in tort (including negligence), 147 | contract, or otherwise, unless required by applicable law (such as deliberate 148 | and grossly negligent acts) or agreed to in writing, shall any Contributor be 149 | liable to You for damages, including any direct, indirect, special, incidental, 150 | or consequential damages of any character arising as a result of this License or 151 | out of the use or inability to use the Work (including but not limited to 152 | damages for loss of goodwill, work stoppage, computer failure or malfunction, or 153 | any and all other commercial damages or losses), even if such Contributor has 154 | been advised of the possibility of such damages. 155 | 156 | 9. Accepting Warranty or Additional Liability. 157 | 158 | While redistributing the Work or Derivative Works thereof, You may choose to 159 | offer, and charge a fee for, acceptance of support, warranty, indemnity, or 160 | other liability obligations and/or rights consistent with this License. However, 161 | in accepting such obligations, You may act only on Your own behalf and on Your 162 | sole responsibility, not on behalf of any other Contributor, and only if You 163 | agree to indemnify, defend, and hold each Contributor harmless for any liability 164 | incurred by, or claims asserted against, such Contributor by reason of your 165 | accepting any such warranty or additional liability. 166 | 167 | END OF TERMS AND CONDITIONS 168 | 169 | APPENDIX: How to apply the Apache License to your work 170 | 171 | To apply the Apache License to your work, attach the following boilerplate 172 | notice, with the fields enclosed by brackets "{}" replaced with your own 173 | identifying information. (Don't include the brackets!) The text should be 174 | enclosed in the appropriate comment syntax for the file format. We also 175 | recommend that a file or class name and description of purpose be included on 176 | the same "printed page" as the copyright notice for easier identification within 177 | third-party archives. 178 | 179 | Copyright 2014-2016 Coding (https://coding.net/) 180 | 181 | Licensed under the Apache License, Version 2.0 (the "License"); 182 | you may not use this file except in compliance with the License. 183 | You may obtain a copy of the License at 184 | 185 | http://www.apache.org/licenses/LICENSE-2.0 186 | 187 | Unless required by applicable law or agreed to in writing, software 188 | distributed under the License is distributed on an "AS IS" BASIS, 189 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 190 | See the License for the specific language governing permissions and 191 | limitations under the License. 192 | -------------------------------------------------------------------------------- /src/org/coding/git/ui/CodingNetSettingsPanel.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 | --------------------------------------------------------------------------------