Example #1
0
File: card.go Project: kesyn/kanban
// CreateCard create new card on board
func CreateCard(u *User, provider string, form *CardRequest) (*Card, int, error) {
	var cr *Card
	var code int
	switch provider {
	case "gitlab":
		c := gitlab.NewContext(u.Credential["gitlab"].Token, u.Credential["gitlab"].PrivateToken)
		r, res, err := c.CreateIssue(strconv.FormatInt(form.ProjectId, 10), mapCardRequestToGitlab(form))
		if err != nil {
			return nil, res.StatusCode, err
		}

		cr = mapCardFromGitlab(r)
	}

	return cr, code, nil
}
Example #2
0
// CreateMilestone create new milestone on board
func CreateMilestone(u *User, provider string, form *MilestoneRequest) (*Milestone, int, error) {
	var cr *Milestone
	var code int
	switch provider {
	case "gitlab":
		c := gitlab.NewContext(u.Credential["gitlab"].Token, u.Credential["gitlab"].PrivateToken)
		r, res, err := c.CreateMilestone(fmt.Sprintf("%d", form.ProjectID), mapMilestoneRequestToGitlab(form))
		if err != nil {
			return nil, res.StatusCode, err
		}

		cr = mapMilestoneFromGitlab(r)
	}

	return cr, code, nil
}
Example #3
0
File: user.go Project: kesyn/kanban
// LoadByToken is
func LoadByToken(u *User, provider string) (*User, error) {
	var user *User
	switch provider {
	case "gitlab":
		c := gitlab.NewContext(u.Credential["gitlab"].Token, u.Credential["gitlab"].PrivateToken)
		r, err := c.CurrentUser()

		if err != nil {
			return nil, err
		}
		user = mapUserFromGitlab(r)
		user.Credential = u.Credential
		user.Credential[provider].PrivateToken = r.PrivateToken
	}

	return user, nil
}
Example #4
0
// ConfigureBoard creates default stages for board
func ConfigureBoard(u *User, provider string, f *BoardRequest) (int, error) {
	switch provider {
	case "gitlab":
		c := gitlab.NewContext(u.Credential["gitlab"].Token, u.Credential["gitlab"].PrivateToken)

		for _, stage := range defaultStages {
			_, res, err := c.CreateLabel(f.BoardId, &gitlab.LabelRequest{
				Name:  stage,
				Color: "#F5F5F5",
			})

			if err != nil {
				return res.StatusCode, err
			}
		}
	}

	return 0, nil
}
Example #5
0
// ItemBoard returns board item
func ItemBoard(u *User, provider string, board_id string) (*Board, error) {
	var b *Board
	switch provider {
	case "gitlab":
		c := gitlab.NewContext(u.Credential["gitlab"].Token, u.Credential["gitlab"].PrivateToken)
		r, err := c.ItemProject(board_id)

		if err, ok := err.(gitlab.ResponseError); ok {
			return nil, ReceivedDataErr{err.Error(), err.StatusCode}
		}

		if err != nil {
			return nil, err
		}
		b = mapBoardFromGitlab(r)
	}

	return b, nil
}
Example #6
0
File: user.go Project: kesyn/kanban
// ListMembers is
func ListMembers(u *User, provider, board_id string) ([]*User, error) {
	var mem []*User
	switch provider {
	case "gitlab":
		c := gitlab.NewContext(u.Credential["gitlab"].Token, u.Credential["gitlab"].PrivateToken)
		r, err := c.ListProjectMembers(board_id, &gitlab.ListOptions{
			Page:    "1",
			PerPage: "100",
		})

		if err != nil {
			return nil, err
		}

		b, err := ItemBoard(u, provider, board_id)
		fmt.Printf("%+v", b)

		if err != nil {
			return nil, err
		}

		exist := make(map[string]bool)

		if b.Owner == nil {
			u, _ := c.ListGroupMembers(fmt.Sprintf("%d", b.Namespace.Id), &gitlab.ListOptions{})

			for _, item := range u {
				exist[item.Username] = true
				mem = append(mem, mapUserFromGitlab(item))
			}
		}

		for _, item := range r {
			if !exist[item.Username] {
				mem = append(mem, mapUserFromGitlab(item))
			}
		}
	}

	return mem, nil
}
Example #7
0
// ListLabels returns list kanban labels for board
func ListLabels(u *User, provider, board_id string) ([]*Label, error) {
	var l []*Label
	switch provider {
	case "gitlab":
		c := gitlab.NewContext(u.Credential["gitlab"].Token, u.Credential["gitlab"].PrivateToken)
		r, err := c.ListLabels(board_id, &gitlab.ListOptions{
			Page:    "1",
			PerPage: "100",
		})

		if err != nil {
			return nil, err
		}

		for _, v := range r {
			l = append(l, mapLabelFromGitlab(v))
		}
	}

	return l, nil
}
Example #8
0
// CreateComment creates a new comment to a single board card.
func CreateComment(u *User, provider string, form *CommentRequest) (*Comment, int, error) {
	var b *Comment
	var code int
	switch provider {
	case "gitlab":
		c := gitlab.NewContext(u.Credential["gitlab"].Token, u.Credential["gitlab"].PrivateToken)
		r, res, err := c.CreateComment(
			strconv.FormatInt(form.ProjectId, 10),
			strconv.FormatInt(form.CardId, 10),
			mapCommentRequestToGitlab(form),
		)

		if err != nil {
			return nil, res.StatusCode, err
		}

		b = mapCommentFromGitlab(r)
	}

	return b, code, nil
}
Example #9
0
// ListComments gets a list of all comment for a single card.
func ListComments(u *User, provider, project_id, card_id string) ([]*Comment, error) {
	b := make([]*Comment, 0)
	switch provider {
	case "gitlab":
		c := gitlab.NewContext(u.Credential["gitlab"].Token, u.Credential["gitlab"].PrivateToken)
		r, err := c.ListComments(project_id, card_id, &gitlab.ListOptions{
			Page:    "1",
			PerPage: "100",
		})

		if err != nil {
			return nil, err
		}

		for _, co := range r {
			b = append(b, mapCommentFromGitlab(co))
		}
	}

	return b, nil
}
Example #10
0
// ListMilestones returns list milestones by project
func ListMilestones(u *User, provider, board_id string) ([]*Milestone, error) {
	var mem []*Milestone
	switch provider {
	case "gitlab":
		c := gitlab.NewContext(u.Credential["gitlab"].Token, u.Credential["gitlab"].PrivateToken)
		r, err := c.ListMilestones(board_id, &gitlab.ListOptions{
			Page:    "1",
			PerPage: "100",
		})

		if err != nil {
			return nil, err
		}

		for _, item := range r {
			mem = append(mem, mapMilestoneFromGitlab(item))
		}
	}

	return mem, nil
}
Example #11
0
// ListBoards returns list board for view user
func ListBoards(u *User, provider string) ([]*Board, error) {
	var b []*Board
	switch provider {
	case "gitlab":
		c := gitlab.NewContext(u.Credential["gitlab"].Token, u.Credential["gitlab"].PrivateToken)

		op := &gitlab.ProjectListOptions{}
		op.Page = "1"
		op.PerPage = "100"
		op.Archived = "false"

		r, err := c.ListProjects(op)

		if err != nil {
			return nil, err
		}

		for _, item := range r {
			b = append(b, mapBoardFromGitlab(item))
		}
	}

	return b, nil
}
Example #12
0
File: card.go Project: kesyn/kanban
// ListCards returns list card
func ListCards(u *User, provider, board_id string) ([]*Card, error) {
	var b []*Card
	switch provider {
	case "gitlab":
		c := gitlab.NewContext(u.Credential["gitlab"].Token, u.Credential["gitlab"].PrivateToken)
		op := &gitlab.IssueListOptions{
			State: "opened",
		}
		op.Page = "1"
		op.PerPage = "200"

		r, err := c.ListIssues(board_id, op)

		if err != nil {
			return nil, err
		}

		for _, d := range r {
			b = append(b, mapCardFromGitlab(d))
		}
	}

	return b, nil
}
Example #13
0
func New(t *oauth2.Token, pt string) GitLabDataSource {
	c := gitlabclient.NewContext(t, pt)

	return GitLabDataSource{client: c}
}