Skip to content

Commit

Permalink
🐛 Fix issue with downloading icons
Browse files Browse the repository at this point in the history
This resolves #1, an issue where emoji icons would never successfully
download, by adapting to changes in the structure and location of the
gitmoji list published upstream by carloscuesta/gitmoji
  • Loading branch information
pghk committed Jul 29, 2023
1 parent 958f4b7 commit 1e0e92c
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 44 deletions.
9 changes: 2 additions & 7 deletions cmd/gitmoji/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func run() {

log.Printf("[main] query=%s", query)

cacheData := map[string][]internal.Gitmoji{}
cacheData := []internal.Gitmoji{}
if wf.Cache.Exists(cacheName) {
if err := wf.Cache.LoadJSON(cacheName, &cacheData); err != nil {
wf.FatalError(err)
Expand All @@ -67,12 +67,7 @@ func run() {
}
}

gitmojidex, cacheOk := cacheData["gitmojis"]
if !cacheOk {
wf.Fatal("Error parsing cached gitmoji index")
}

for _, gitmoji := range gitmojidex {
for _, gitmoji := range cacheData {
internal.BuildItem(&gitmoji, wf, client)
}

Expand Down
2 changes: 1 addition & 1 deletion configs/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
<key>userconfigurationconfig</key>
<array/>
<key>version</key>
<string>0.9.0</string>
<string>0.9.1</string>
<key>webaddress</key>
<string>https://github.com/pghk/alfred-go-gitmoji</string>
</dict>
Expand Down
17 changes: 10 additions & 7 deletions internal/get_gitmoji.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ import (
)

const GithubUrl string = "https://raw.githubusercontent.com"
const GitmojiIndex string = "carloscuesta/gitmoji/master/src/data/gitmojis.json"
const GitmojiUrl string = "carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json"
const IconLibrary string = "joypixels/emoji-assets/master/png/128/"

func GetGitmoji(client *http.Client) (map[string][]Gitmoji, error) {
func GetGitmoji(client *http.Client) ([]Gitmoji, error) {
gitmojiJson := getGitmojiList(client)
return toMap(gitmojiJson)
}

type GitmojiIndex struct {
Gitmojis []Gitmoji `json:"gitmojis"`
}
type Gitmoji struct {
Emoji string `json:"emoji"`
Entity string `json:"entity"`
Expand All @@ -28,10 +31,10 @@ type Gitmoji struct {
Semver interface{} `json:"semver"`
}

func toMap(input string) (map[string][]Gitmoji, error) {
test := map[string][]Gitmoji{}
err := json.Unmarshal([]byte(input), &test)
return test, err
func toMap(input string) ([]Gitmoji, error) {
var index GitmojiIndex
err := json.Unmarshal([]byte(input), &index)
return index.Gitmojis, err
}

// iconName derives PNG filenames from emoji, according to the convention used by JoyPixels in their repository
Expand All @@ -57,7 +60,7 @@ func (g *Gitmoji) iconFile() string {
}

func getGitmojiList(client *http.Client) string {
resp, err := client.Get(GithubUrl + "/" + GitmojiIndex)
resp, err := client.Get(GithubUrl + "/" + GitmojiUrl)
if err != nil {
log.Fatalln(err)
}
Expand Down
5 changes: 4 additions & 1 deletion internal/get_gitmoji_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ func Test_getGitmojiList(t *testing.T) {
client, vcr := setup("gitmoji_index")
ja := jsonassert.New(t)

ja.Assertf(getGitmojiList(client), `{"gitmojis": "<<PRESENCE>>"}`)
ja.Assertf(getGitmojiList(client), `{
"$schema": "<<PRESENCE>>",
"gitmojis": "<<PRESENCE>>"
}`)

teardown(vcr)
}
Expand Down
22 changes: 12 additions & 10 deletions test/_fixtures/gitmoji_index.yaml

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions test/_fixtures/item_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,14 @@ interactions:
- default-src 'none'; style-src 'unsafe-inline'; sandbox
Content-Type:
- image/png
Cross-Origin-Resource-Policy:
- cross-origin
Date:
- Sun, 21 Aug 2022 06:01:19 GMT
- Sat, 29 Jul 2023 05:19:23 GMT
Etag:
- W/"93a04fd0813face3f0baf503b6958da12ce5e1c61e5f7530b4f18eb7b5bca677"
Expires:
- Sun, 21 Aug 2022 06:06:19 GMT
- Sat, 29 Jul 2023 05:24:23 GMT
Source-Age:
- "0"
Strict-Transport-Security:
Expand All @@ -267,23 +269,23 @@ interactions:
Via:
- 1.1 varnish
X-Cache:
- MISS
- HIT
X-Cache-Hits:
- "0"
- "1"
X-Content-Type-Options:
- nosniff
X-Fastly-Request-Id:
- c2a54a59eaa986f7a25857468b9bd2ac192d1906
- e7248f4298c199dbef90ad10e7469792c233b31d
X-Frame-Options:
- deny
X-Github-Request-Id:
- 82DC:5E96:C4A749:101ADEF:6301CA2F
- 2C0E:27A8:90E6A:B55A0:64C4A026
X-Served-By:
- cache-bos4667-BOS
- cache-bos4626-BOS
X-Timer:
- S1661061680.799855,VS0,VE80
- S1690607964.738976,VS0,VE114
X-Xss-Protection:
- 1; mode=block
status: 200 OK
code: 200
duration: 94.889866ms
duration: 129.645854ms
20 changes: 11 additions & 9 deletions test/_fixtures/load_icon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,14 @@ interactions:
- default-src 'none'; style-src 'unsafe-inline'; sandbox
Content-Type:
- image/png
Cross-Origin-Resource-Policy:
- cross-origin
Date:
- Sun, 21 Aug 2022 06:01:19 GMT
- Sat, 29 Jul 2023 05:19:23 GMT
Etag:
- W/"80e9e1a6e00d6aae9bec0e4339edda13344eeffff2ca5b1ff9eda4beb010aa11"
Expires:
- Sun, 21 Aug 2022 06:06:19 GMT
- Sat, 29 Jul 2023 05:24:23 GMT
Source-Age:
- "0"
Strict-Transport-Security:
Expand All @@ -140,23 +142,23 @@ interactions:
Via:
- 1.1 varnish
X-Cache:
- MISS
- HIT
X-Cache-Hits:
- "0"
- "1"
X-Content-Type-Options:
- nosniff
X-Fastly-Request-Id:
- 9f8ece0350d30ecfea83820eea2e1a82e79ddf97
- ee153e2d1f6611eb74bd0c5e4c9f2bf01380dfac
X-Frame-Options:
- deny
X-Github-Request-Id:
- 12A4:45F9:BC6902:F8BF58:6301CA2F
- B0FA:3472:AADC5:CF575:64C4A022
X-Served-By:
- cache-bos4667-BOS
- cache-bos4626-BOS
X-Timer:
- S1661061680.519833,VS0,VE119
- S1690607964.545025,VS0,VE76
X-Xss-Protection:
- 1; mode=block
status: 200 OK
code: 200
duration: 140.536808ms
duration: 98.157021ms

0 comments on commit 1e0e92c

Please sign in to comment.