Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions custom/conf/app.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,9 @@ LEVEL = Info
;; Disable stars feature.
;DISABLE_STARS = false
;;
;; Disable star lists feature.
;DISABLE_STAR_LISTS = false
;;
;; The default branch name of new repositories
;DEFAULT_BRANCH = main
;;
Expand Down
1 change: 1 addition & 0 deletions docs/content/administration/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ In addition, there is _`StaticRootPath`_ which can be set as a built-in at build
- `PREFIX_ARCHIVE_FILES`: **true**: Prefix archive files by placing them in a directory named after the repository.
- `DISABLE_MIGRATIONS`: **false**: Disable migrating feature.
- `DISABLE_STARS`: **false**: Disable stars feature.
- `DISABLE_STAR_LISTS`: **false**: Disable star lists feature.
- `DEFAULT_BRANCH`: **main**: Default branch name of all repositories.
- `ALLOW_ADOPTION_OF_UNADOPTED_REPOSITORIES`: **false**: Allow non-admin users to adopt unadopted repositories
- `ALLOW_DELETION_OF_UNADOPTED_REPOSITORIES`: **false**: Allow non-admin users to delete unadopted repositories
Expand Down
5 changes: 5 additions & 0 deletions models/fixtures/star.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@
id: 2
uid: 2
repo_id: 4

-
id: 3
uid: 1
repo_id: 1
20 changes: 20 additions & 0 deletions models/fixtures/star_list.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-
id: 1
user_id: 1
name: "First List"
description: "Description for first List"
is_private: false

-
id: 2
user_id: 1
name: "Second List"
description: "This is private"
is_private: true

-
id: 3
user_id: 2
name: "Third List"
description: "It's a Secret to Everybody"
is_private: false
4 changes: 4 additions & 0 deletions models/fixtures/star_list_repos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-
id: 1
star_list_id: 1
repo_id: 1
6 changes: 6 additions & 0 deletions models/repo/repo_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ type SearchRepoOptions struct {
OrderBy db.SearchOrderBy
Private bool // Include private repositories in results
StarredByID int64
StarListID int64
WatchedByID int64
AllPublic bool // Include also all public repositories of users and public organisations
AllLimited bool // Include also all public repositories of limited organisations
Expand Down Expand Up @@ -372,6 +373,11 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
cond = cond.And(builder.In("id", builder.Select("repo_id").From("star").Where(builder.Eq{"uid": opts.StarredByID})))
}

// Restrict to repos in a star list
if opts.StarListID > 0 {
cond = cond.And(builder.In("id", builder.Select("repo_id").From("star_list_repos").Where(builder.Eq{"star_list_id": opts.StarListID})))
}

// Restrict to watched repositories
if opts.WatchedByID > 0 {
cond = cond.And(builder.In("id", builder.Select("repo_id").From("watch").Where(builder.Eq{"user_id": opts.WatchedByID})))
Expand Down
4 changes: 4 additions & 0 deletions models/repo/star.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func StarRepo(ctx context.Context, userID, repoID int64, star bool) error {
if _, err := db.Exec(ctx, "UPDATE `user` SET num_stars = num_stars - 1 WHERE id = ?", userID); err != nil {
return err
}
// Delete the repo from all star lists of this user
if _, err := db.Exec(ctx, "DELETE FROM star_list_repos WHERE repo_id = ? AND star_list_id IN (SELECT id FROM star_list WHERE user_id = ?)", repoID, userID); err != nil {
return err
}
}

return committer.Commit()
Expand Down
Loading