Example #1
0
func mention(c *integram.Context, member *api.Actor) string {
	userName := ""
	c.ServiceCache("nick_map_"+member.UUID, &userName)
	if userName == "" {
		return m.Bold(member.DisplayName)
	}
	return "@" + userName
}
Example #2
0
func mention(c *integram.Context, name string, email string) string {
	userName := ""
	c.ServiceCache("nick_map_"+name, &userName)
	if userName == "" && email != "" {
		c.ServiceCache("nick_map_"+email, &userName)
	}
	if userName == "" {
		return m.Bold(name)
	}
	return "@" + userName
}
Example #3
0
func prInlineButtonPressed(c *integram.Context, fullRepoName string, prID int) error {
	if ok, err := mustBeAuthed(c); !ok {
		return err
	}
	pr := api.PullRequest{}

	c.ServiceCache(issueUniqueID(fullRepoName, prID), &pr)

	switch c.Callback.Data {
	case "back":
		return c.EditPressedInlineKeyboard(prInlineKeyboard(&pr))
	case "assign":
		//rest.Repositories.ListPublic()
	}
	return nil

}
Example #4
0
func issueInlineButtonPressed(c *integram.Context, fullRepoName string, issueID int) error {

	if ok, err := mustBeAuthed(c); !ok {
		return err
	}

	issue := api.Issue{}

	c.ServiceCache(issueUniqueID(fullRepoName, issueID), &issue)
	rest := client(c)

	fmt.Printf("issueID: %d\n", issueID)
	owner, repo := splitRepo(fullRepoName)

	if c.Callback.Message.InlineKeyboardMarkup.State == "status" {
		state := c.Callback.Data
		if state != "back" {
			err := rest.Repositories.Issues.SetState(&api.IssuesOptions{Owner: owner, Repo_slug: repo, Issue_id: issueID, State: state})
			if err != nil {
				return err
			}
			issue.State = state
			storeIssue(c, &issue)

			c.Callback.Data = "back"
		}
	}
	switch c.Callback.Data {
	case "back":
		return c.EditPressedInlineKeyboard(issueInlineKeyboard(&issue))
	/*case "assign":
	case "status":
		buttons := integram.InlineButtons{}
		for b, _ := range issueStates {
			if !strings.EqualFold(b, issue.State) {
				buttons.Append(b, strings.ToUpper(b[0:1])+b[1:])
			}
		}
		buttons.Append("back", "← Back")

		return c.EditPressedInlineKeyboard(buttons.Markup(1, "status"))
	*/
	case "vote":
		me, err := me(rest, c)

		if err != nil {
			return err
		}

		if integram.SliceContainsString(issue.VotedActorsUUID, me.UUID) {
			err = rest.Repositories.Issues.Unvote(&api.IssuesOptions{Owner: owner, Repo_slug: repo, Issue_id: issueID})
			if err != nil {
				return err
			}
			b := issue.VotedActorsUUID[:0]
			for _, x := range issue.VotedActorsUUID {
				if x != me.UUID {
					b = append(b, x)
				}
			}
			issue.VotedActorsUUID = b
			issue.Votes--

		} else {
			err = rest.Repositories.Issues.Vote(&api.IssuesOptions{Owner: owner, Repo_slug: repo, Issue_id: issueID})
			if err != nil {
				return err
			}
			issue.Votes++
			issue.VotedActorsUUID = append(issue.VotedActorsUUID, me.UUID)
		}
		storeIssue(c, &issue)

		kb := issueInlineKeyboard(&issue)
		err = c.EditPressedInlineKeyboard(kb)

		if err != nil {
			return err
		}
	}

	return nil

}