Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support export to postman customize workspace #524

Merged
merged 28 commits into from
Aug 8, 2021

Conversation

gcdd1993
Copy link
Contributor

feature #283

@gcdd1993 gcdd1993 changed the title Support export to postman customize workspace feat: Support export to postman customize workspace Jun 28, 2021
@gcdd1993
Copy link
Contributor Author

@tangcent ubuntu CI test不知道怎么没通过,看了一下没看明白怎么修改。本地倒是可以运行的

@tangcent
Copy link
Owner

本地执行: ./gradlew check --stacktrace


PostmanWorkspaceChecker没有配置默认实现,postman相关的测试用例都无法通过。
要么配ImplementedBy,要么在测试用例里用到的地方都手动配一下。

@gcdd1993
Copy link
Contributor Author

本地执行: ./gradlew check --stacktrace

PostmanWorkspaceChecker没有配置默认实现,postman相关的测试用例都无法通过。
要么配ImplementedBy,要么在测试用例里用到的地方都手动配一下。

本地执行./gradlew check --stacktrace成功了,但是CI check ...,求助求助
image

@tangcent
Copy link
Owner

PostmanFormatterTest里缺少注入:
可以执行: ./gradlew :idea-plugin:test --stacktrace --tests "com.itangcent.idea.plugin.api.export.postman.PostmanFormatterTest.testRequest2Item"

com.google.inject.ConfigurationException: Guice configuration errors:

1) No implementation for com.itangcent.idea.plugin.api.export.postman.PostmanApiHelper was bound.
  while locating com.itangcent.idea.plugin.api.export.postman.PostmanApiHelper
    for field at com.itangcent.idea.plugin.settings.helper.PostmanSettingsHelper.postmanApiHelper(PostmanSettingsHelper.kt:21)
  while locating com.itangcent.idea.plugin.settings.helper.PostmanSettingsHelper
    for field at com.itangcent.idea.plugin.api.export.postman.PostmanFormatter.postmanSettingsHelper(PostmanFormatter.kt:33)
  while locating com.itangcent.idea.plugin.api.export.postman.PostmanFormatter
    for field at com.itangcent.idea.plugin.api.export.postman.PostmanFormatterTest.postmanFormatter(PostmanFormatterTest.kt:23)
  while locating com.itangcent.idea.plugin.api.export.postman.PostmanFormatterTest

2) No implementation for com.itangcent.idea.plugin.settings.helper.PostmanWorkspaceChecker was bound.
  while locating com.itangcent.idea.plugin.settings.helper.PostmanWorkspaceChecker
    for field at com.itangcent.idea.plugin.settings.helper.PostmanSettingsHelper.postmanWorkspaceChecker(PostmanSettingsHelper.kt:21)
  while locating com.itangcent.idea.plugin.settings.helper.PostmanSettingsHelper
    for field at com.itangcent.idea.plugin.api.export.postman.PostmanFormatter.postmanSettingsHelper(PostmanFormatter.kt:33)
  while locating com.itangcent.idea.plugin.api.export.postman.PostmanFormatter
    for field at com.itangcent.idea.plugin.api.export.postman.PostmanFormatterTest.postmanFormatter(PostmanFormatterTest.kt:23)
  while locating com.itangcent.idea.plugin.api.export.postman.PostmanFormatterTest

2 errors
	at com.google.inject.internal.InjectorImpl.getMembersInjector(InjectorImpl.java:1023)
	at com.google.inject.internal.InjectorImpl.getMembersInjector(InjectorImpl.java:1029)
	at com.google.inject.internal.InjectorImpl.injectMembers(InjectorImpl.java:1013)
	at com.itangcent.intellij.context.ActionContext.init(ActionContext.kt:428)
	at com.itangcent.testFramework.ContextLightCodeInsightFixtureTestCase.setUp(ContextLightCodeInsightFixtureTestCase.kt:86)
	at com.intellij.testFramework.UsefulTestCase.defaultRunBare(UsefulTestCase.java:380)
	at com.intellij.testFramework.EdtTestUtil$Companion$runInEdtAndWait$1.invoke(EdtTestUtil.kt:29)
	at com.intellij.testFramework.EdtTestUtil$Companion$runInEdtAndWait$1.invoke(EdtTestUtil.kt:27)
	at com.intellij.testFramework.EdtTestUtilKt$runInEdtAndWait$2.run(EdtTestUtil.kt:62)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:301)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
	at java.awt.EventQueue.access$500(EventQueue.java:97)
	at java.awt.EventQueue$3.run(EventQueue.java:709)
	at java.awt.EventQueue$3.run(EventQueue.java:703)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:346)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

@gcdd1993
Copy link
Contributor Author

PostmanFormatterTest里缺少注入:
可以执行: ./gradlew :idea-plugin:test --stacktrace --tests "com.itangcent.idea.plugin.api.export.postman.PostmanFormatterTest.testRequest2Item"

com.google.inject.ConfigurationException: Guice configuration errors:

1) No implementation for com.itangcent.idea.plugin.api.export.postman.PostmanApiHelper was bound.
  while locating com.itangcent.idea.plugin.api.export.postman.PostmanApiHelper
    for field at com.itangcent.idea.plugin.settings.helper.PostmanSettingsHelper.postmanApiHelper(PostmanSettingsHelper.kt:21)
  while locating com.itangcent.idea.plugin.settings.helper.PostmanSettingsHelper
    for field at com.itangcent.idea.plugin.api.export.postman.PostmanFormatter.postmanSettingsHelper(PostmanFormatter.kt:33)
  while locating com.itangcent.idea.plugin.api.export.postman.PostmanFormatter
    for field at com.itangcent.idea.plugin.api.export.postman.PostmanFormatterTest.postmanFormatter(PostmanFormatterTest.kt:23)
  while locating com.itangcent.idea.plugin.api.export.postman.PostmanFormatterTest

2) No implementation for com.itangcent.idea.plugin.settings.helper.PostmanWorkspaceChecker was bound.
  while locating com.itangcent.idea.plugin.settings.helper.PostmanWorkspaceChecker
    for field at com.itangcent.idea.plugin.settings.helper.PostmanSettingsHelper.postmanWorkspaceChecker(PostmanSettingsHelper.kt:21)
  while locating com.itangcent.idea.plugin.settings.helper.PostmanSettingsHelper
    for field at com.itangcent.idea.plugin.api.export.postman.PostmanFormatter.postmanSettingsHelper(PostmanFormatter.kt:33)
  while locating com.itangcent.idea.plugin.api.export.postman.PostmanFormatter
    for field at com.itangcent.idea.plugin.api.export.postman.PostmanFormatterTest.postmanFormatter(PostmanFormatterTest.kt:23)
  while locating com.itangcent.idea.plugin.api.export.postman.PostmanFormatterTest

2 errors
	at com.google.inject.internal.InjectorImpl.getMembersInjector(InjectorImpl.java:1023)
	at com.google.inject.internal.InjectorImpl.getMembersInjector(InjectorImpl.java:1029)
	at com.google.inject.internal.InjectorImpl.injectMembers(InjectorImpl.java:1013)
	at com.itangcent.intellij.context.ActionContext.init(ActionContext.kt:428)
	at com.itangcent.testFramework.ContextLightCodeInsightFixtureTestCase.setUp(ContextLightCodeInsightFixtureTestCase.kt:86)
	at com.intellij.testFramework.UsefulTestCase.defaultRunBare(UsefulTestCase.java:380)
	at com.intellij.testFramework.EdtTestUtil$Companion$runInEdtAndWait$1.invoke(EdtTestUtil.kt:29)
	at com.intellij.testFramework.EdtTestUtil$Companion$runInEdtAndWait$1.invoke(EdtTestUtil.kt:27)
	at com.intellij.testFramework.EdtTestUtilKt$runInEdtAndWait$2.run(EdtTestUtil.kt:62)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:301)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
	at java.awt.EventQueue.access$500(EventQueue.java:97)
	at java.awt.EventQueue$3.run(EventQueue.java:709)
	at java.awt.EventQueue$3.run(EventQueue.java:703)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:346)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

@gcdd1993 gcdd1993 closed this Jun 29, 2021
@gcdd1993 gcdd1993 reopened this Jun 29, 2021
@codecov-commenter
Copy link

codecov-commenter commented Jun 29, 2021

Codecov Report

Merging #524 (df7b9fd) into master (10cbc70) will increase coverage by 2.373%.
The diff coverage is 19.592%.

Impacted file tree graph

@@               Coverage Diff               @@
##              master      #524       +/-   ##
===============================================
+ Coverage     39.596%   41.969%   +2.373%     
- Complexity      1492      1677      +185     
===============================================
  Files            197       203        +6     
  Lines          11491     12495     +1004     
  Branches        2580      2923      +343     
===============================================
+ Hits            4550      5244      +694     
- Misses          5956      6220      +264     
- Partials         985      1031       +46     
Flag Coverage Δ
unittests 41.969% <19.592%> (+2.373%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...tangcent/idea/plugin/actions/ApiDashBoardAction.kt 0.000% <0.000%> (ø)
...angcent/idea/plugin/actions/PostmanExportAction.kt 0.000% <0.000%> (ø)
...m/itangcent/idea/plugin/actions/SuvExportAction.kt 0.000% <0.000%> (ø)
...ugin/api/export/postman/DefaultPostmanApiHelper.kt 2.203% <0.000%> (+2.203%) ⬆️
...ea/plugin/api/export/postman/PostmanApiExporter.kt 0.000% <0.000%> (ø)
...idea/plugin/api/export/postman/PostmanApiHelper.kt 0.000% <ø> (ø)
...i/export/postman/PostmanWorkspaceCheckerSupport.kt 0.000% <0.000%> (ø)
...gcent/idea/plugin/api/export/suv/SuvApiExporter.kt 0.000% <0.000%> (ø)
...itangcent/idea/plugin/dialog/ApiDashboardDialog.kt 0.000% <0.000%> (ø)
.../itangcent/idea/plugin/dialog/EasyApiSettingGUI.kt 0.000% <0.000%> (ø)
... and 40 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 10cbc70...df7b9fd. Read the comment docs.

@tangcent
Copy link
Owner

@gcdd1993 以下Action也需要注入PostmanWorkspaceChecker:

override fun afterBuildActionContext(event: AnActionEvent, builder: ActionContext.ActionContextBuilder) {
super.afterBuildActionContext(event, builder)
builder.bind(LocalFileRepository::class) { it.with(DefaultLocalFileRepository::class).singleton() }
//allow cache api
builder.bind(ClassExporter::class, "delegate_classExporter") {
it.with(CompositeClassExporter::class).singleton()
}
builder.bindInstance(
"AVAILABLE_CLASS_EXPORTER",
arrayOf<Any>(
SpringRequestClassExporter::class,
GenericRequestClassExporter::class
)
)
builder.bind(ClassExporter::class) { it.with(CachedRequestClassExporter::class).singleton() }
builder.bind(ConfigReader::class, "delegate_config_reader") { it.with(PostmanConfigReader::class).singleton() }
builder.bind(ConfigReader::class) { it.with(RecommendConfigReader::class).singleton() }
builder.bind(HttpClientProvider::class) { it.with(ConfigurableHttpClientProvider::class).singleton() }
builder.bind(RequestBuilderListener::class) { it.with(ComponentRequestBuilderListener::class).singleton() }
builder.bindInstance("AVAILABLE_REQUEST_BUILDER_LISTENER", arrayOf<Any>(DefaultRequestBuilderListener::class, PostmanRequestBuilderListener::class))
builder.bind(ActiveWindowProvider::class) { it.with(SimpleActiveWindowProvider::class) }
}

override fun afterBuildActionContext(
actionContext: ActionContext,
builder: ActionContext.ActionContextBuilder
) {
super.afterBuildActionContext(actionContext, builder)
builder.bind(LocalFileRepository::class) { it.with(DefaultLocalFileRepository::class).singleton() }
builder.bind(PostmanApiHelper::class) { it.with(PostmanCachedApiHelper::class).singleton() }
builder.bind(HttpClientProvider::class) { it.with(ConfigurableHttpClientProvider::class).singleton() }
builder.bind(FormatFolderHelper::class) { it.with(PostmanFormatFolderHelper::class).singleton() }
builder.bind(ConfigReader::class, "delegate_config_reader") {
it.with(PostmanConfigReader::class).singleton()
}
builder.bind(ConfigReader::class) { it.with(RecommendConfigReader::class).singleton() }
builder.bind(ClassExporter::class) { it.with(CompositeClassExporter::class).singleton() }
builder.bindInstance(
"AVAILABLE_CLASS_EXPORTER",
arrayOf<Any>(
SpringRequestClassExporter::class,
GenericRequestClassExporter::class
)
)
builder.bind(RequestBuilderListener::class) { it.with(ComponentRequestBuilderListener::class).singleton() }
builder.bindInstance(
"AVAILABLE_REQUEST_BUILDER_LISTENER",
arrayOf<Any>(DefaultRequestBuilderListener::class, PostmanRequestBuilderListener::class)
)
//always not read api from cache
builder.bindInstance("class.exporter.read.cache", false)
builder.bindInstance("file.save.default", "postman.json")
builder.bindInstance("file.save.last.location.key", "com.itangcent.postman.export.path")
}

logger!!.error("Authentication failed!")
return
}
val returnObj = returnValue.asJsonElement()
val errorName = returnObj
.sub("error")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些格式化的改动最好去掉,会对review产生干扰。
如果需要做格式化、整理import、修复typo等,可以单独提交一个PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

抱歉,我来恢复一下,IDEA自动给我格式化了

return null
}

private fun selectWorkspace(module: String): String? {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tangcent selectWorkspaceprivate的方法,这个有什么办法可以写单元测试吗?

@@ -104,12 +114,18 @@ open class DefaultPostmanApiHelper : PostmanApiHelper {
* @return collection id
*/
override fun createCollection(collection: HashMap<String, Any?>): HashMap<String, Any?>? {

// get workspace
val module = actionContext.callInReadUI { moduleHelper.findModuleByPath(ActionUtils.findCurrentPath()) }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在这一步获取module无法处理这种情况: UserCtrl.java#L16-L20
当我尝试导出spring-demo或者仅导出UserCtrl.java时, 均只提示我选择springboot-demo对应的WorkSpace,而没有提示我选择user 对应的WorkSpace


需要根据开发者是否有一个项目下的接口导入多个WorkSpace的需求来处理这个问题:

  1. 如果没有的话,直接关联Project->WorkSpace是不是更合理?
  2. 如果有的话,就比较麻烦了,需要改造:
    private fun doParseRequests(requests: MutableList<Request>): HashMap<String, Any?> {
    //parse [request...] ->
    // {
    // "module":{
    // "folder":[request...]
    // }
    // }
    val moduleFolderApiMap: HashMap<String, HashMap<Folder, ArrayList<HashMap<String, Any?>>>> = HashMap()

    在对module进行分组聚合后,再对它们归属的workspace进行分组聚合

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我觉得直接关联Project -> WorkSpace更为合理。
是我理解错了,我原先的想法就是一个Project导入一个WorkSpace,错把module当成project

@gcdd1993
Copy link
Contributor Author

@tangcent ApiDashboard这样改一下是否会更好一点?
如果用户为本项目配置过workspace,则选中该workspace,如果没有,则不选中任何workspace
image

@tangcent
Copy link
Owner

@tangcent ApiDashboard这样改一下是否会更好一点?
如果用户为本项目配置过workspace,则选中该workspace,如果没有,则不选中任何workspace
image

LGTM

@gcdd1993
Copy link
Contributor Author

1、已完成并自测ApiDashboard选择workspace并导入collection
Snipaste_2021-07-13_11-25-57
2、快捷键导出至自定义workspace

@tangcent tangcent added the type: new feature Add New Feature label Jul 13, 2021
@stale
Copy link

stale bot commented Aug 3, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Aug 3, 2021
@stale stale bot closed this Aug 8, 2021
@tangcent tangcent reopened this Aug 8, 2021
@stale stale bot removed the wontfix This will not be worked on label Aug 8, 2021
@tangcent
Copy link
Owner

tangcent commented Aug 8, 2021

@gcdd1993 先合进来再改?

@gcdd1993
Copy link
Contributor Author

gcdd1993 commented Aug 8, 2021

@gcdd1993 先合进来再改?

额,还需要改啥,上面的都改好了

@tangcent tangcent merged commit 928159b into tangcent:master Aug 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: new feature Add New Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants