|
|
@ -12,6 +12,8 @@ import ( |
|
|
"strings" |
|
|
"strings" |
|
|
|
|
|
|
|
|
"bytes" |
|
|
"bytes" |
|
|
|
|
|
"html" |
|
|
|
|
|
|
|
|
log "github.com/Sirupsen/logrus" |
|
|
log "github.com/Sirupsen/logrus" |
|
|
gogithub "github.com/google/go-github/github" |
|
|
gogithub "github.com/google/go-github/github" |
|
|
"github.com/matrix-org/go-neb/database" |
|
|
"github.com/matrix-org/go-neb/database" |
|
|
@ -20,7 +22,6 @@ import ( |
|
|
"github.com/matrix-org/go-neb/services/github/client" |
|
|
"github.com/matrix-org/go-neb/services/github/client" |
|
|
"github.com/matrix-org/go-neb/types" |
|
|
"github.com/matrix-org/go-neb/types" |
|
|
"github.com/matrix-org/gomatrix" |
|
|
"github.com/matrix-org/gomatrix" |
|
|
"html" |
|
|
|
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
// ServiceType of the Github service
|
|
|
// ServiceType of the Github service
|
|
|
@ -450,8 +451,8 @@ func (s *Service) expandCommit(roomID, userID, owner, repo, sha string) interfac |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
log.WithError(err).WithFields(log.Fields{ |
|
|
log.WithError(err).WithFields(log.Fields{ |
|
|
"owner": owner, |
|
|
"owner": owner, |
|
|
"repo": repo, |
|
|
|
|
|
"sha": sha, |
|
|
|
|
|
|
|
|
"repo": repo, |
|
|
|
|
|
"sha": sha, |
|
|
}).Print("Failed to fetch commit") |
|
|
}).Print("Failed to fetch commit") |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
@ -460,9 +461,9 @@ func (s *Service) expandCommit(roomID, userID, owner, repo, sha string) interfac |
|
|
var htmlBuffer bytes.Buffer |
|
|
var htmlBuffer bytes.Buffer |
|
|
var plainBuffer bytes.Buffer |
|
|
var plainBuffer bytes.Buffer |
|
|
|
|
|
|
|
|
shortUrl := strings.TrimSuffix(*c.HTMLURL, *c.SHA) + sha |
|
|
|
|
|
htmlBuffer.WriteString(fmt.Sprintf("<a href=\"%s\">%s</a><br />", *c.HTMLURL, shortUrl)) |
|
|
|
|
|
plainBuffer.WriteString(fmt.Sprintf("%s\n", shortUrl)) |
|
|
|
|
|
|
|
|
shortURL := strings.TrimSuffix(*c.HTMLURL, *c.SHA) + sha |
|
|
|
|
|
htmlBuffer.WriteString(fmt.Sprintf("<a href=\"%s\">%s</a><br />", *c.HTMLURL, shortURL)) |
|
|
|
|
|
plainBuffer.WriteString(fmt.Sprintf("%s\n", shortURL)) |
|
|
|
|
|
|
|
|
if c.Stats != nil { |
|
|
if c.Stats != nil { |
|
|
htmlBuffer.WriteString(fmt.Sprintf("[<strong><font color='#1cc3ed'>~%d</font>, <font color='#30bf2b'>+%d</font>, <font color='#fc3a25'>-%d</font></strong>] ", len(c.Files), *c.Stats.Additions, *c.Stats.Deletions)) |
|
|
htmlBuffer.WriteString(fmt.Sprintf("[<strong><font color='#1cc3ed'>~%d</font>, <font color='#30bf2b'>+%d</font>, <font color='#fc3a25'>-%d</font></strong>] ", len(c.Files), *c.Stats.Additions, *c.Stats.Deletions)) |
|
|
@ -744,7 +745,7 @@ func getTokenForUser(realmID, userID string) (string, error) { |
|
|
return "", fmt.Errorf("Session is not a github session: %s", session.ID()) |
|
|
return "", fmt.Errorf("Session is not a github session: %s", session.ID()) |
|
|
} |
|
|
} |
|
|
if ghSession.AccessToken == "" { |
|
|
if ghSession.AccessToken == "" { |
|
|
return "", fmt.Errorf("Github auth session for %s has not been completed.", userID) |
|
|
|
|
|
|
|
|
return "", fmt.Errorf("Github auth session for %s has not been completed", userID) |
|
|
} |
|
|
} |
|
|
return ghSession.AccessToken, nil |
|
|
return ghSession.AccessToken, nil |
|
|
} |
|
|
} |
|
|
|