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

Do not store inactive repos without any resources #1658

Merged
merged 17 commits into from
Mar 21, 2023

Conversation

qwerty287
Copy link
Contributor

Do not sync repos with forge if the repo is not necessary in DB.

In the DB, only repos that were active once or repos that are currently active are stored. When trying to enable new repos, the repos list is fetched from the forge instead and displayed directly. In addition to this, the forge func Perm was removed and is now merged with Repo.

Solves a TODO on RepoBatch.

@qwerty287 qwerty287 added the refactor delete or replace old code label Mar 20, 2023
@qwerty287 qwerty287 added this to the 1.0.0 milestone Mar 20, 2023
@qwerty287 qwerty287 requested a review from a team March 20, 2023 17:03
Copy link
Member

@anbraten anbraten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this fix / help with #485?

How are repo permission now handled? From a first look you check if a user is having and update access on create / activate / re-activate, repair, move and in the repo-middleware if the last sync was 1 hour ago?

server/api/repo.go Outdated Show resolved Hide resolved
server/api/repo.go Outdated Show resolved Hide resolved
server/api/repo.go Show resolved Hide resolved
server/model/repo.go Show resolved Hide resolved
@qwerty287
Copy link
Contributor Author

Does this fix / help with #485?

I think yes, at least partially.

How are repo permission now handled? From a first look you check if a user is having and update access on create / activate / re-activate, repair, move and in the repo-middleware if the last sync was 1 hour ago?

Yes, I think that's correct. Didn't change much from before though.

server/api/repo.go Outdated Show resolved Hide resolved
server/api/user.go Outdated Show resolved Hide resolved
@qwerty287
Copy link
Contributor Author

qwerty287 commented Mar 21, 2023

As for #485, this definitely prepares it. I think I can create a new PR that closes it after this one because this is out of scope for this one.

This is actually more similar to it than I originally thought. I'm working on partially fixing it.

@codecov-commenter

This comment was marked as outdated.

@qwerty287
Copy link
Contributor Author

OK, I removed support for flat permissions as it was completely unused in 4e16b8f. This also was the first task from #485. The second one is not related to this PR and should be done separately.

@anbraten anbraten enabled auto-merge (squash) March 21, 2023 17:20
@6543
Copy link
Member

6543 commented Mar 21, 2023

Does this fix / help with #485?

did not had a deeper look into it ... but if we only request permissions on demand (by having a paginated view on the repo activation page ...)

owner := c.Param("owner")
name := c.Param("name")
repo, err := _store.GetRepoName(owner + "/" + name)
enabledOnce := err == nil // if there's no error, the repo was found and enabled once already
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would expizite check against errorNotFound

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be done below

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm well it's not the usual code-style but you are right

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff --git a/server/api/repo.go b/server/api/repo.go
index 64db2f80..da7eccf7 100644
--- a/server/api/repo.go
+++ b/server/api/repo.go
@@ -42,14 +42,19 @@ func PostRepo(c *gin.Context) {
 
        owner := c.Param("owner")
        name := c.Param("name")
+       enabledOnce := false
        repo, err := _store.GetRepoName(owner + "/" + name)
-       enabledOnce := err == nil // if there's no error, the repo was found and enabled once already
+       if err != nil {
+               if !errors.Is(err, types.RecordNotExist) {
+                       // we got an unexpected error
+                       _ = c.AbortWithError(http.StatusInternalServerError, err)
+                       return
+               }
+               enabledOnce = true
+       }
        if enabledOnce && repo.IsActive {
                c.String(http.StatusConflict, "Repository is already active.")
                return
-       } else if err != nil && !errors.Is(err, types.RecordNotExist) {
-               c.String(http.StatusInternalServerError, err.Error())
-               return
        }

not sure if it's worth changing it to that or not

@anbraten anbraten merged commit 0970f35 into woodpecker-ci:master Mar 21, 2023
@qwerty287 qwerty287 deleted the only-active branch March 22, 2023 06:39
@xoxys xoxys mentioned this pull request Nov 9, 2023
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor delete or replace old code server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants