From f321e01a3eb0e95b854652324bfedb607e1f6f7b Mon Sep 17 00:00:00 2001 From: Ivan Semenov Date: Fri, 27 Jul 2018 19:26:06 +0300 Subject: [PATCH] [github] Better access token name --- .../authentication/ui/GithubLoginDialog.kt | 5 ++--- .../authentication/util/GithubTokenCreator.kt | 16 ++++++++++------ .../github/tasks/GithubRepositoryEditor.java | 2 +- .../jetbrains/plugins/github/util/GithubUtil.kt | 1 - 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/plugins/github/src/org/jetbrains/plugins/github/authentication/ui/GithubLoginDialog.kt b/plugins/github/src/org/jetbrains/plugins/github/authentication/ui/GithubLoginDialog.kt index b2fca9dd756d..79fe9cd7d6fc 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/authentication/ui/GithubLoginDialog.kt +++ b/plugins/github/src/org/jetbrains/plugins/github/authentication/ui/GithubLoginDialog.kt @@ -37,7 +37,6 @@ import org.jetbrains.plugins.github.exceptions.GithubParseException import org.jetbrains.plugins.github.ui.util.DialogValidationUtils.chain import org.jetbrains.plugins.github.ui.util.DialogValidationUtils.notBlank import org.jetbrains.plugins.github.ui.util.Validator -import org.jetbrains.plugins.github.util.GithubUtil import java.awt.Component import java.awt.Cursor import java.net.UnknownHostException @@ -71,7 +70,7 @@ class GithubLoginDialog @JvmOverloads constructor(private val executorFactory: G private lateinit var login: String private lateinit var token: String - var tokenNote: String = GithubUtil.DEFAULT_TOKEN_NOTE + var clientName: String = GithubTokenCreator.DEFAULT_CLIENT_NAME private var tokenAcquisitionError: ValidationInfo? = null init { @@ -277,7 +276,7 @@ class GithubLoginDialog @JvmOverloads constructor(private val executorFactory: G indicator: ProgressIndicator): Pair { if (!isAccountUnique(loginTextField.text, server)) throw LoginNotUniqueException() - val token = GithubTokenCreator(server, executor, indicator).createMaster(tokenNote).token + val token = GithubTokenCreator(server, executor, indicator).createMaster(clientName).token return loginTextField.text to token } diff --git a/plugins/github/src/org/jetbrains/plugins/github/authentication/util/GithubTokenCreator.kt b/plugins/github/src/org/jetbrains/plugins/github/authentication/util/GithubTokenCreator.kt index 6f89f3150dde..dbff5c754fcf 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/authentication/util/GithubTokenCreator.kt +++ b/plugins/github/src/org/jetbrains/plugins/github/authentication/util/GithubTokenCreator.kt @@ -1,9 +1,11 @@ // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.plugins.github.authentication.util +import com.intellij.openapi.application.ApplicationNamesInfo import com.intellij.openapi.progress.ProgressIndicator -import org.jetbrains.plugins.github.api.GithubApiRequests +import org.jetbrains.annotations.Nls import org.jetbrains.plugins.github.api.GithubApiRequestExecutor +import org.jetbrains.plugins.github.api.GithubApiRequests import org.jetbrains.plugins.github.api.GithubServerPath import org.jetbrains.plugins.github.api.data.GithubAuthorization import org.jetbrains.plugins.github.exceptions.GithubStatusCodeException @@ -15,12 +17,9 @@ import java.io.IOException class GithubTokenCreator(private val server: GithubServerPath, private val executor: GithubApiRequestExecutor, private val indicator: ProgressIndicator) { - - private val MASTER_SCOPES = listOf("repo", "gist") - @Throws(IOException::class) - fun createMaster(note: String): GithubAuthorization { - return safeCreate(MASTER_SCOPES, note) + fun createMaster(@Nls(capitalization = Nls.Capitalization.Title) noteSuffix: String): GithubAuthorization { + return safeCreate(MASTER_SCOPES, ApplicationNamesInfo.getInstance().fullProductName + " " + noteSuffix + " access token") } @Throws(IOException::class) @@ -45,4 +44,9 @@ class GithubTokenCreator(private val server: GithubServerPath, throw e } } + + companion object { + private val MASTER_SCOPES = listOf("repo", "gist") + const val DEFAULT_CLIENT_NAME = "Github Integration Plugin" + } } \ No newline at end of file diff --git a/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java b/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java index 4cb2f78ee85d..b8bf1947b96f 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java +++ b/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java @@ -122,7 +122,7 @@ public class GithubRepositoryEditor extends BaseRepositoryEditor