Skip to content

Commit

Permalink
Fix token
Browse files Browse the repository at this point in the history
  • Loading branch information
syuchan1005 committed Jul 3, 2020
1 parent cfaec18 commit bfb6fac
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew buildPlugin
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release
id: create_release
uses: actions/create-release@v1
Expand Down
2 changes: 1 addition & 1 deletion EmojiUpdate.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"classPackageName": "com.github.syuchan1005.gitprefix",
"className": "EmojiUtil",
"classMapName": "emojiMap",
"gistToken": "<Your gist token>"
"gistToken": ""
}
13 changes: 9 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.github.kittinunf.fuel.gson.gsonDeserializerOf
buildscript {
repositories {
mavenCentral()
maven(url = "https://www.jitpack.io")
}

dependencies {
Expand Down Expand Up @@ -120,11 +119,16 @@ open class UpdateEmojiTask : DefaultTask() {

private fun fetchGists(emojiNames: List<String>): Map<String, String> {
val config = Config.get()
val gistToken = if (config.gistToken.isEmpty()) {
System.getenv("GITHUB_TOKEN")
} else {
config.gistToken
}
val (_, _, createData) = Fuel
.post("https://api.github.com/gists")
.jsonBody("{\"files\":{\"test.md\":{\"content\":\"${emojiNames.map { ":$it:" }
.joinToString(":", ":", ":")}\"}}}")
.authentication().bearer(config.gistToken)
.authentication().bearer(gistToken)
.responseObject(gsonDeserializerOf(GistResponse.Create::class.java))
val (createResult, _) = createData

Expand Down Expand Up @@ -155,7 +159,7 @@ open class UpdateEmojiTask : DefaultTask() {

val deleteRes = Fuel
.delete("https://api.github.com/gists/${createResult.id}")
.authentication().bearer(config.gistToken)
.authentication().bearer(gistToken)
.response()

if (deleteRes.second.statusCode != 204) {
Expand Down Expand Up @@ -208,7 +212,8 @@ ${emojiList.map { (k, v) -> " \"$k\" to EmojiData(\"$v\", IconLoa

fun get(): Config {
if (config == null) {
val file = File("./EmojiUpdate.json")
var file = File("./EmojiUpdate.json")
if (!file.exists()) file = File("./EmojiUpdate.template.json")
config = com.google.gson.Gson()
.fromJson(file.reader(), Config::class.java)
}
Expand Down

0 comments on commit bfb6fac

Please sign in to comment.