Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
Fix LGTM.app bug (#32)
Browse files Browse the repository at this point in the history
* Update README.md

* Fix bug in LGTM.app

* Fix README.md
  • Loading branch information
micnncim authored Dec 14, 2019
1 parent a20edfa commit 4ebeb6f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

![](docs/assets/screen-record.gif)

Send LGTM reaction as image or GIF when we say `lgtm`.
Send LGTM reaction as image when we say `lgtm`.

Currently supports [LGTM.app](https://www.lgtm.app) and [GIPHY](https://giphy.com).

Expand Down
29 changes: 25 additions & 4 deletions pkg/lgtm/lgtmapp/lgtmapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ func NewClient() (*client, error) {
}

func (c *client) GetRandom() (string, error) {
imageURL, err := c.getRandomImageURL()
if err != nil {
return "", nil
}
return lgtm.MarkdownStyle(imageURL), nil
}

func (c *client) getRandomImageURL() (string, error) {
log := c.log

req, err := http.NewRequest(http.MethodGet, randomURL, nil)
Expand All @@ -50,9 +58,22 @@ func (c *client) GetRandom() (string, error) {
return "", nil
}

// strip image url from lgtm.app data url.
// e.g.) https://www.lgtm.app/i/4F5vFPNW3 -> https://www.lgtm.app/p/4F5vFPNW3
redirectedURL := resp.Request.URL.String()
slugs := strings.Split(redirectedURL, "/")
id := slugs[len(slugs)-1]
imageURL := fmt.Sprintf(imageURLFormat, id)
return lgtm.MarkdownStyle(imageURL), nil
s := strings.Split(redirectedURL, "/")
id := s[len(s)-1]
u := fmt.Sprintf(imageURLFormat, id)

req, err = http.NewRequest(http.MethodGet, u, nil)
if err != nil {
log.Error("unable to create new http request", zap.Error(err))
return "", nil
}
resp, err = c.httpClient.Do(req)
if err != nil {
log.Error("unable to do http request", zap.Error(err))
return "", nil
}
return resp.Request.URL.String(), nil
}

0 comments on commit 4ebeb6f

Please sign in to comment.