Skip to content

Commit 0d3d346

Browse files
committed
fix intellij github api removal issue
1 parent ddf647c commit 0d3d346

23 files changed

+198
-393
lines changed

build.gradle

+4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ version "${version}"
1515
sourceCompatibility = JavaVersion.VERSION_1_8
1616

1717
repositories {
18+
mavenLocal()
1819
mavenCentral()
1920
}
2021

2122
dependencies {
23+
// https://mvnrepository.com/artifact/org.kohsuke/github-api
24+
implementation(files("libs/github-api-1.309-SNAPSHOT.jar"))
25+
2226
testCompile group: 'junit', name: 'junit', version: '4.12'
2327
}
2428

changeNotes.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
<ul>
2-
<li>Migrate deprecated apis</li>
3-
<li>Improve ui operation</li>
2+
<li>Use github-api rather than intellij github plugin</li>
43
</ul>

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version = 1.0.3
1+
version = 1.1.0
22
ideaVersion = IC-2019.1
33
customUtilBuild = 299.*
44
isEAP = false

libs/github-api-1.309-SNAPSHOT.jar

574 KB
Binary file not shown.

src/main/java/com/chuntung/plugin/gistsnippet/action/AddAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020 Tony Ho. Some rights reserved.
2+
* Copyright (c) 2020 Chuntung Ho. Some rights reserved.
33
*/
44

55
package com.chuntung.plugin.gistsnippet.action;

src/main/java/com/chuntung/plugin/gistsnippet/action/CustomComboBoxAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020 Tony Ho. Some rights reserved.
2+
* Copyright (c) 2020 Chuntung Ho. Some rights reserved.
33
*/
44

55
package com.chuntung.plugin.gistsnippet.action;

src/main/java/com/chuntung/plugin/gistsnippet/action/DeleteAction.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020 Tony Ho. Some rights reserved.
2+
* Copyright (c) 2020 Chuntung Ho. Some rights reserved.
33
*/
44

55
package com.chuntung.plugin.gistsnippet.action;
@@ -70,9 +70,9 @@ public void actionPerformed(@NotNull AnActionEvent e) {
7070

7171
@Override
7272
public void run(@NotNull ProgressIndicator indicator) {
73-
GithubAccount account = GithubAccountHolder.getInstance(project).getAccount();
73+
String token = GithubAccountHolder.getInstance(project).getAccessToken();
7474
GistSnippetService service = GistSnippetService.getInstance();
75-
service.deleteGist(account, gistIds);
75+
service.deleteGist(token, gistIds);
7676
deleted = true;
7777
}
7878

src/main/java/com/chuntung/plugin/gistsnippet/action/EditAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020 Tony Ho. Some rights reserved.
2+
* Copyright (c) 2020 Chuntung Ho. Some rights reserved.
33
*/
44

55
package com.chuntung.plugin.gistsnippet.action;

src/main/java/com/chuntung/plugin/gistsnippet/action/InsertAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020 Tony Ho. Some rights reserved.
2+
* Copyright (c) 2020 Chuntung Ho. Some rights reserved.
33
*/
44

55
package com.chuntung.plugin.gistsnippet.action;

src/main/java/com/chuntung/plugin/gistsnippet/action/OpenInBrowserAction.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
/*
2-
* Copyright (c) 2020 Tony Ho. Some rights reserved.
2+
* Copyright (c) 2020 Chuntung Ho. Some rights reserved.
33
*/
44

55
package com.chuntung.plugin.gistsnippet.action;
66

7+
import com.chuntung.plugin.gistsnippet.dto.FileNodeDTO;
78
import com.chuntung.plugin.gistsnippet.dto.SnippetNodeDTO;
8-
import com.chuntung.plugin.gistsnippet.dto.api.GistFileDTO;
99
import com.intellij.ide.BrowserUtil;
10-
import com.intellij.openapi.actionSystem.AnAction;
1110
import com.intellij.openapi.actionSystem.AnActionEvent;
1211
import com.intellij.openapi.project.DumbAwareAction;
1312
import org.jetbrains.annotations.NotNull;
@@ -34,8 +33,8 @@ public void actionPerformed(@NotNull AnActionEvent e) {
3433
String url = null;
3534
if (userObject instanceof SnippetNodeDTO) {
3635
url = ((SnippetNodeDTO) userObject).getHtmlUrl();
37-
} else if (userObject instanceof GistFileDTO) {
38-
url = ((GistFileDTO) userObject).getRawUrl();
36+
} else if (userObject instanceof FileNodeDTO) {
37+
url = ((FileNodeDTO) userObject).getRawUrl();
3938
}
4039
if (url != null) {
4140
BrowserUtil.open(url);

src/main/java/com/chuntung/plugin/gistsnippet/action/ReloadAction.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*
2-
* Copyright (c) 2020 Tony Ho. Some rights reserved.
2+
* Copyright (c) 2020 Chuntung Ho. Some rights reserved.
33
*/
44

55
package com.chuntung.plugin.gistsnippet.action;
66

7-
import com.chuntung.plugin.gistsnippet.dto.api.GistFileDTO;
7+
import com.chuntung.plugin.gistsnippet.dto.FileNodeDTO;
88
import com.intellij.openapi.actionSystem.AnAction;
99
import com.intellij.openapi.actionSystem.AnActionEvent;
1010
import com.intellij.openapi.project.DumbAware;
@@ -36,7 +36,7 @@ public void actionPerformed(@NotNull AnActionEvent e) {
3636
public void update(@NotNull AnActionEvent e) {
3737
// check if gist file selected
3838
DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
39-
if (!(node.getUserObject() instanceof GistFileDTO)) {
39+
if (!(node.getUserObject() instanceof FileNodeDTO)) {
4040
e.getPresentation().setVisible(false);
4141
}
4242
}

src/main/java/com/chuntung/plugin/gistsnippet/dto/api/GistFileDTO.java renamed to src/main/java/com/chuntung/plugin/gistsnippet/dto/FileNodeDTO.java

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
* Copyright (c) 2020 Tony Ho. Some rights reserved.
2+
* Copyright (c) 2020 Chuntung Ho. Some rights reserved.
33
*/
44

5-
package com.chuntung.plugin.gistsnippet.dto.api;
5+
package com.chuntung.plugin.gistsnippet.dto;
66

77
import com.google.gson.annotations.SerializedName;
88
import com.intellij.ide.projectView.PresentationData;
@@ -13,8 +13,9 @@
1313
import com.intellij.ui.SimpleTextAttributes;
1414
import com.intellij.ui.treeStructure.SimpleNode;
1515
import org.jetbrains.annotations.NotNull;
16+
import org.kohsuke.github.GHGistFile;
1617

17-
public class GistFileDTO extends SimpleNode {
18+
public class FileNodeDTO extends SimpleNode {
1819
private String filename;
1920
private String type;
2021
private String language;
@@ -26,6 +27,19 @@ public class GistFileDTO extends SimpleNode {
2627
private Boolean truncated;
2728
private String content;
2829

30+
public FileNodeDTO() {
31+
}
32+
33+
public FileNodeDTO(GHGistFile gistFile) {
34+
this.setFilename(gistFile.getFileName());
35+
this.setContent(gistFile.getContent());
36+
this.setLanguage(gistFile.getLanguage());
37+
this.setRawUrl(gistFile.getRawUrl());
38+
this.setType(gistFile.getType());
39+
this.setSize((long) gistFile.getSize());
40+
this.setTruncated(gistFile.isTruncated());
41+
}
42+
2943
public String getFilename() {
3044
return filename;
3145
}
@@ -102,7 +116,7 @@ protected PresentationData createPresentation() {
102116
}
103117

104118
@NotNull
105-
public static FileType getFileType(GistFileDTO dto) {
119+
public static FileType getFileType(FileNodeDTO dto) {
106120
FileTypeManager fileTypeManager = FileTypeManager.getInstance();
107121
FileType fileType = fileTypeManager.getFileTypeByFileName(dto.getFilename());
108122
if (UnknownFileType.INSTANCE == fileType) {

src/main/java/com/chuntung/plugin/gistsnippet/dto/ScopeEnum.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020 Tony Ho. Some rights reserved.
2+
* Copyright (c) 2020 Chuntung Ho. Some rights reserved.
33
*/
44

55
package com.chuntung.plugin.gistsnippet.dto;

src/main/java/com/chuntung/plugin/gistsnippet/dto/SnippetNodeDTO.java

+46-34
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
/*
2-
* Copyright (c) 2020 Tony Ho. Some rights reserved.
2+
* Copyright (c) 2020 Chuntung Ho. Some rights reserved.
33
*/
44

55
package com.chuntung.plugin.gistsnippet.dto;
66

7-
import com.chuntung.plugin.gistsnippet.dto.api.GistDTO;
8-
import com.chuntung.plugin.gistsnippet.dto.api.GistFileDTO;
9-
import com.chuntung.plugin.gistsnippet.dto.api.GistOwnerDTO;
107
import com.intellij.ide.projectView.PresentationData;
118
import com.intellij.openapi.util.IconLoader;
129
import com.intellij.ui.SimpleTextAttributes;
1310
import com.intellij.ui.treeStructure.SimpleNode;
1411
import org.jetbrains.annotations.NotNull;
12+
import org.kohsuke.github.GHGist;
13+
import org.kohsuke.github.GHGistFile;
14+
import org.kohsuke.github.GHUser;
1515

1616
import javax.swing.*;
17+
import java.io.IOException;
1718
import java.net.MalformedURLException;
1819
import java.net.URL;
1920
import java.util.*;
@@ -37,9 +38,9 @@ public class SnippetNodeDTO extends SimpleNode {
3738
private String htmlUrl;
3839
private String description;
3940
private Integer filesCount;
40-
private List<GistFileDTO> files;
41+
private List<FileNodeDTO> files;
4142
private List<String> tags;
42-
private GistOwnerDTO owner;
43+
private GHUser owner;
4344
private boolean isPublic;
4445
private String createdAt;
4546
private String updatedAt;
@@ -100,11 +101,11 @@ public void setFilesCount(Integer filesCount) {
100101
this.filesCount = filesCount;
101102
}
102103

103-
public List<GistFileDTO> getFiles() {
104+
public List<FileNodeDTO> getFiles() {
104105
return files;
105106
}
106107

107-
public void setFiles(List<GistFileDTO> files) {
108+
public void setFiles(List<FileNodeDTO> files) {
108109
this.files = files;
109110
}
110111

@@ -116,11 +117,11 @@ public void setTags(List<String> tags) {
116117
this.tags = tags;
117118
}
118119

119-
public GistOwnerDTO getOwner() {
120+
public GHUser getOwner() {
120121
return owner;
121122
}
122123

123-
public void setOwner(GistOwnerDTO owner) {
124+
public void setOwner(GHUser owner) {
124125
this.owner = owner;
125126
}
126127

@@ -207,30 +208,38 @@ private void render(PresentationData presentation) {
207208
presentation.setTooltip(tooltip);
208209
}
209210

210-
static SnippetNodeDTO of(GistDTO dto, ScopeEnum scope) {
211+
static SnippetNodeDTO of(GHGist dto, ScopeEnum scope) {
211212
SnippetNodeDTO node = new SnippetNodeDTO();
212213
node.setScope(scope);
213-
node.setId(dto.getId());
214-
node.setHtmlUrl(dto.getHtmlUrl());
215-
node.setCreatedAt(dto.getCreatedAt());
216-
node.setUpdatedAt(dto.getUpdatedAt());
217-
node.setPublic(dto.getPublic());
218-
node.setOwner(dto.getOwner());
214+
node.setId(dto.getGistId());
215+
node.setHtmlUrl(dto.getHtmlUrl().toString());
216+
try {
217+
node.setCreatedAt(dto.getCreatedAt().toString());
218+
node.setUpdatedAt(dto.getUpdatedAt().toString());
219+
node.setOwner(dto.getOwner());
220+
} catch (IOException e) {
221+
// NOOP
222+
}
223+
node.setPublic(dto.isPublic());
219224
node.setFilesCount(dto.getFiles().size());
220-
node.setFiles(new ArrayList<>(dto.getFiles().values()));
225+
List<FileNodeDTO> files = new ArrayList<>();
226+
for (GHGistFile gistFile : dto.getFiles().values()) {
227+
files.add(new FileNodeDTO(gistFile));
228+
}
229+
node.setFiles(files);
221230

222231
parseDescription(dto, node);
223232

224233
return node;
225234
}
226235

227-
private static void parseDescription(GistDTO dto, SnippetNodeDTO node) {
236+
private static void parseDescription(GHGist dto, SnippetNodeDTO node) {
228237
node.setTitle(null);
229238
node.setTags(null);
230239
if (dto.getDescription() == null || dto.getDescription().isEmpty()) {
231240
// set description as first file name if empty
232-
for (GistFileDTO fileDTO : dto.getFiles().values()) {
233-
node.setDescription(fileDTO.getFilename());
241+
for (GHGistFile fileDTO : dto.getFiles().values()) {
242+
node.setDescription(fileDTO.getFileName());
234243
break;
235244
}
236245
} else {
@@ -257,25 +266,28 @@ private static void parseDescription(GistDTO dto, SnippetNodeDTO node) {
257266
}
258267
}
259268

260-
public boolean update(GistDTO dto) {
269+
public boolean update(GHGist dto) {
261270
boolean updated = false;
262-
if (!Objects.equals(createdAt, dto.getCreatedAt()) || !Objects.equals(updatedAt, dto.getUpdatedAt())) {
263-
parseDescription(dto, this);
264-
265-
setPublic(dto.getPublic());
266-
setCreatedAt(dto.getCreatedAt());
267-
setUpdatedAt(dto.getUpdatedAt());
271+
try {
272+
if (!Objects.equals(createdAt, dto.getCreatedAt()) || !Objects.equals(updatedAt, dto.getUpdatedAt())) {
273+
parseDescription(dto, this);
274+
setPublic(dto.isPublic());
275+
setCreatedAt(dto.getCreatedAt().toString());
276+
setUpdatedAt(dto.getUpdatedAt().toString());
268277

269-
updated = true;
278+
updated = true;
279+
}
280+
} catch (IOException e) {
281+
throw new RuntimeException(e);
270282
}
271283

272284
// merge files
273285
setFilesCount(dto.getFiles().size());
274286
Set<String> children = new HashSet<>();
275287
// traverse tree structure to remove non-existing items
276-
Iterator<GistFileDTO> iterator = getFiles().iterator();
288+
Iterator<FileNodeDTO> iterator = getFiles().iterator();
277289
while (iterator.hasNext()) {
278-
GistFileDTO fileDTO = iterator.next();
290+
FileNodeDTO fileDTO = iterator.next();
279291
if (dto.getFiles().containsKey(fileDTO.getFilename())) {
280292
fileDTO.setContent(dto.getFiles().get(fileDTO.getFilename()).getContent());
281293
children.add(fileDTO.getFilename());
@@ -286,10 +298,10 @@ public boolean update(GistDTO dto) {
286298
}
287299

288300
// traverse latest files to add missing items if gist changed
289-
for (GistFileDTO fileDTO : dto.getFiles().values()) {
290-
if (!children.contains(fileDTO.getFilename())) {
301+
for (GHGistFile gistFile : dto.getFiles().values()) {
302+
if (!children.contains(gistFile.getFileName())) {
291303
updated = true;
292-
getFiles().add(fileDTO);
304+
getFiles().add(new FileNodeDTO(gistFile));
293305
}
294306
}
295307

src/main/java/com/chuntung/plugin/gistsnippet/dto/SnippetRootNode.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
2-
* Copyright (c) 2020 Tony Ho. Some rights reserved.
2+
* Copyright (c) 2020 Chuntung Ho. Some rights reserved.
33
*/
44

55
package com.chuntung.plugin.gistsnippet.dto;
66

7-
import com.chuntung.plugin.gistsnippet.dto.api.GistDTO;
87
import com.intellij.ui.treeStructure.SimpleNode;
98
import org.jetbrains.annotations.NotNull;
9+
import org.kohsuke.github.GHGist;
1010

1111
import java.util.ArrayList;
1212
import java.util.Collections;
@@ -28,9 +28,9 @@ public SimpleNode[] getChildren() {
2828
return children == null ? NO_CHILDREN : children.toArray(NO_CHILDREN);
2929
}
3030

31-
public void resetChildren(List<GistDTO> gistList, ScopeEnum scope) {
31+
public void resetChildren(List<GHGist> gistList, ScopeEnum scope) {
3232
List<SnippetNodeDTO> children = new ArrayList<>(gistList.size());
33-
for (GistDTO gistDTO : gistList) {
33+
for (GHGist gistDTO : gistList) {
3434
children.add(SnippetNodeDTO.of(gistDTO, scope));
3535
}
3636
this.children = children;

0 commit comments

Comments
 (0)