Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patcito/projects enhancements #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/ethantkoenig/rupture v0.0.0-20181029165146-c3b3b810dc77 h1:ZLWiTTzTUBb0WEXUxobYI/RxULIzOoIP7pgfDd4p1cw=
github.com/ethantkoenig/rupture v0.0.0-20181029165146-c3b3b810dc77/go.mod h1:MkKY/CB98aVE4VxO63X5vTQKUgcn+3XP15LMASe3lYs=
github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51 h1:0JZ+dUmQeA8IIVUMzysrX4/AKuQwWhV2dYQuPZdvdSQ=
github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64=
Expand Down Expand Up @@ -655,6 +656,7 @@ github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0f
github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v1.1.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jarcoal/httpmock v0.0.0-20180424175123-9c70cfe4a1da/go.mod h1:ks+b9deReOc7jgqp+e7LuFiCBH6Rm5hL32cLcEAArb4=
github.com/jaytaylor/html2text v0.0.0-20200412013138-3577fbdbcff7 h1:g0fAGBisHaEQ0TRq1iBvemFRf+8AEWEmBESSiWB3Vsc=
github.com/jaytaylor/html2text v0.0.0-20200412013138-3577fbdbcff7/go.mod h1:CVKlgaMiht+LXvHG173ujK6JUhZXKb2u/BQtjPDIvyk=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
Expand Down Expand Up @@ -684,6 +686,7 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4=
github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd h1:Coekwdh0v2wtGp9Gmz1Ze3eVRAWJMLokvN3QjdzCHLY=
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
Expand Down Expand Up @@ -1025,6 +1028,7 @@ github.com/spf13/viper v1.7.0 h1:xVKxvI7ouOI5I+U9s2eeiUfMaWBVoXA3AWskkrqK0VM=
github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
github.com/spf13/viper v1.7.1 h1:pM5oEahlgWv/WnHXpgbKz7iLIxRf65tye2Ci+XFK5sk=
github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf h1:pvbZ0lM0XWPBqUKqFU8cmavspvIl9nulOYwdy6IFRRo=
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf/go.mod h1:RJID2RhlZKId02nZ62WenDCkgHFerpIOmW0iT7GKmXM=
github.com/steveyen/gtreap v0.1.0 h1:CjhzTa274PyJLJuMZwIzCO1PfC00oRa8d1Kc78bFXJM=
github.com/steveyen/gtreap v0.1.0/go.mod h1:kl/5J7XbrOmlIbYIXdRHDDE5QxHqpk0cmkT7Z4dM9/Y=
Expand Down Expand Up @@ -1069,6 +1073,7 @@ github.com/unknwon/com v1.0.1/go.mod h1:tOOxU81rwgoCLoOVVPHb6T/wt8HZygqH5id+GNnl
github.com/unknwon/i18n v0.0.0-20190805065654-5c6446a380b6/go.mod h1:+5rDk6sDGpl3azws3O+f+GpFSyN9GVr0K8cvQLQM2ZQ=
github.com/unknwon/i18n v0.0.0-20200823051745-09abd91c7f2c h1:679/gJXwrsHC3RATr0YYjZvDMJPYN7W9FGSGNoLmKxM=
github.com/unknwon/i18n v0.0.0-20200823051745-09abd91c7f2c/go.mod h1:+5rDk6sDGpl3azws3O+f+GpFSyN9GVr0K8cvQLQM2ZQ=
github.com/unknwon/paginater v0.0.0-20200328080006-042474bd0eae h1:ihaXiJkaca54IaCSnEXtE/uSZOmPxKZhDfVLrzZLFDs=
github.com/unknwon/paginater v0.0.0-20200328080006-042474bd0eae/go.mod h1:1fdkY6xxl6ExVs2QFv7R0F5IRZHKA8RahhB9fMC9RvM=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
Expand Down
26 changes: 21 additions & 5 deletions models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
api "code.gitea.io/gitea/modules/structs"
Expand Down Expand Up @@ -63,6 +64,7 @@ type Issue struct {
Reactions ReactionList `xorm:"-"`
TotalTrackedTime int64 `xorm:"-"`
Assignees []*User `xorm:"-"`
ProjectIssueID ProjectIssue

// IsLocked limits commenting abilities to users on an issue
// with write access
Expand Down Expand Up @@ -1100,8 +1102,10 @@ type IssuesOptions struct {
ExcludedLabelNames []string
SortType string
IssueIDs []int64
ExcludeProjectID int64
// prioritize issues from this repo
PriorityRepoID int64
PriorityRepoID int64
RenderEmojiTitle util.OptionalBool
}

// sortIssuesSession sort an issues-related session based on the provided
Expand Down Expand Up @@ -1180,17 +1184,21 @@ func (opts *IssuesOptions) setupSession(sess *xorm.Session) {

if opts.ProjectID > 0 {
sess.Join("INNER", "project_issue", "issue.id = project_issue.issue_id").
And("project_issue.project_id=?", opts.ProjectID)
And("project_issue.project_id=?", opts.ProjectID).OrderBy("`project_issue`.priority")
}

if opts.ProjectBoardID != 0 {
if opts.ProjectBoardID > 0 {
sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_board_id": opts.ProjectBoardID}))
sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_board_id": opts.ProjectBoardID}).OrderBy("`project_issue`.priority"))
} else {
sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_board_id": 0}))
sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_board_id": 0}).OrderBy("`project_issue`.priority"))
}
}

if opts.ExcludeProjectID != 0 {
sess.NotIn("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_id": opts.ExcludeProjectID}).OrderBy("`project_issue`.priority"))
}

switch opts.IsPull {
case util.OptionalBoolTrue:
sess.And("issue.is_pull=?", true)
Expand Down Expand Up @@ -1280,7 +1288,15 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) {
if err := IssueList(issues).LoadAttributes(); err != nil {
return nil, fmt.Errorf("LoadAttributes: %v", err)
}

if opts.RenderEmojiTitle == util.OptionalBoolTrue {
var issuesWithEmojis []*Issue
for _, issue := range issues {
title := string(markup.RenderEmoji(issue.Title))
issue.Title = title
issuesWithEmojis = append(issuesWithEmojis, issue)
}
return issuesWithEmojis, nil
}
return issues, nil
}

Expand Down
2 changes: 2 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ var migrations = []Migration{
NewMigration("ensure repo topics are up-to-date", fixRepoTopics),
// v158 -> v159
NewMigration("code comment replies should have the commitID of the review they are replying to", updateCodeCommentReplies),
// v159 -> v160
NewMigration("Add projects boards and issues priorities", addProjectsIssuesBoardsPriority),
}

// GetCurrentDBVersion returns the current db version
Expand Down
26 changes: 26 additions & 0 deletions models/migrations/v159.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package migrations

import (
"xorm.io/xorm"
)

func addProjectsIssuesBoardsPriority(x *xorm.Engine) error {
// ProjectIssue saves relation from issue to a project
type ProjectIssue struct {
Priority int `xorm:"NOT NULL DEFAULT 0"`
}

if err := x.Sync2(new(ProjectIssue)); err != nil {
return err
}

type ProjectBoard struct {
Priority int `xorm:"NOT NULL DEFAULT 0"`
}

return x.Sync2(new(ProjectBoard))
}
23 changes: 23 additions & 0 deletions models/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"errors"
"fmt"

"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
Expand Down Expand Up @@ -47,6 +48,7 @@ type Project struct {
IsClosed bool `xorm:"INDEX"`
BoardType ProjectBoardType
Type ProjectType
Repo *Repository `xorm:"-"`

RenderedContent string `xorm:"-"`

Expand Down Expand Up @@ -305,3 +307,24 @@ func deleteProjectByID(e Engine, id int64) error {

return updateRepositoryProjectCount(e, p.RepoID)
}

// LoadRepository loads repository of a given project
func (p *Project) LoadRepository() error {
return p.loadRepository(x)
}

// loadRepository loads repository of a given project
func (p *Project) loadRepository(e Engine) error {
if p.Repo != nil {
return nil
}
if p.Type == ProjectTypeRepository {
repo := &Repository{}
if _, err := e.ID(p.RepoID).Get(repo); err != nil {
log.Info("failed getting repo %v", err)
return err
}
p.Repo = repo
}
return nil
}
74 changes: 53 additions & 21 deletions models/project_board.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package models

import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil"

Expand Down Expand Up @@ -32,17 +33,19 @@ const (

// ProjectBoard is used to represent boards on a project
type ProjectBoard struct {
ID int64 `xorm:"pk autoincr"`
Title string
Default bool `xorm:"NOT NULL DEFAULT false"` // issues not assigned to a specific board will be assigned to this board
ID int64 `xorm:"pk autoincr"`
Title string
Default bool `xorm:"NOT NULL DEFAULT false"` // issues not assigned to a specific board will be assigned to this board
Priority int `xorm:"NOT NULL DEFAULT 0"`

ProjectID int64 `xorm:"INDEX NOT NULL"`
CreatorID int64 `xorm:"NOT NULL"`

CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`

Issues []*Issue `xorm:"-"`
Issues []*Issue `xorm:"-"`
ProjectIssues []*ProjectIssue `xorm:"-"`
}

// IsProjectBoardTypeValid checks if the project board type is valid
Expand Down Expand Up @@ -174,7 +177,7 @@ func GetProjectBoards(projectID int64) ([]*ProjectBoard, error) {

var boards = make([]*ProjectBoard, 0, 5)

sess := x.Where("project_id=?", projectID)
sess := x.Where("project_id=?", projectID).OrderBy("priority")
return boards, sess.Find(&boards)
}

Expand All @@ -187,34 +190,63 @@ func GetUncategorizedBoard(projectID int64) (*ProjectBoard, error) {
}, nil
}

// LoadIssues load issues assigned to this board
func (b *ProjectBoard) LoadIssues() (IssueList, error) {
// LoadProjectIssues load project issues assigned to this board
func (b *ProjectBoard) LoadProjectIssues() ([]*ProjectIssue, error) {
var boardID int64
if !b.Default {
boardID = b.ID

} else {
// Issues without ProjectBoardID
boardID = -1
boardID = 0
}
issues, err := Issues(&IssuesOptions{
ProjectBoardID: boardID,
ProjectID: b.ProjectID,
})
b.Issues = issues
return issues, err
var projectIssues []*ProjectIssue
var issues []*Issue
if err := x.Table("issue").
Cols("issue.id, issue.repo_id, issue.index, issue.poster_id,issue.name,issue.milestone_id,issue.is_closed,issue.is_pull,issue.created_unix,issue.updated_unix, project_issue.id as project_issue_id, project_issue.project_id as project_issue_project_id, project_issue.project_board_id as project_issue_project_board_id").
Join("INNER", "project_issue", "issue.id = project_issue.issue_id").
Where("project_board_id = ? and project_id =?",
boardID, b.ProjectID).
OrderBy("`project_issue`.priority").Find(&issues); err != nil {
log.Error("LoadAttributes: %v", err)
}

if err := IssueList(issues).LoadAttributes(); err != nil {
log.Error("LoadAttributes: %v", err)
}

for _, issue := range issues {
projectIssue := issue.ProjectIssueID
projectIssue.Issue = issue
projectIssues = append(projectIssues, &projectIssue)
}
return projectIssues, nil
}

// LoadIssues load issues assigned to the boards
func (bs ProjectBoardList) LoadIssues() (IssueList, error) {
issues := make(IssueList, 0, len(bs)*10)
func (bs ProjectBoardList) LoadIssues() error {
for i := range bs {
il, err := bs[i].LoadIssues()
il, err := bs[i].LoadProjectIssues()
if err != nil {
return nil, err
return err
}
bs[i].ProjectIssues = il
}
return nil
}

// UpdateBoardsPriority updates boards priority for a project
func UpdateBoardsPriority(boards []ProjectBoard) error {
sess := x.NewSession()
if err := sess.Begin(); err != nil {
return err
}
defer sess.Close()
for _, board := range boards {
if _, err := sess.ID(board.ID).Cols("priority").Update(&board); err != nil {
log.Info("failed updating board priorities %s", err)
return err
}
bs[i].Issues = il
issues = append(issues, il...)
}
return issues, nil
return sess.Commit()
}
Loading