Skip to content

REST API PATCH Repository Configuration within Organisation #13620

@khmarbaise

Description

@khmarbaise
Member
  • Gitea version (or commit ref):
    • Gitea Version: 1.13.0+rc2
  • Git version:
    • 2.26.2
  • Database (use [x]):
    • PostgreSQL
      MySQL
      MSSQL
      SQLite
  • OS: Linux / Docker Container.

I have created a repository within an organisation and afterwards I've tried to change the settings of that repository.

This change is being done via REST API. In particular I'm trying to change the entries:
ChangeSettings

  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
      No

Example from within IDEA IntelliJ:

PATCH https://try.gitea.io/api/v1/repos/khmtestorga/testrepo
Authorization: Basic khmarbaise PASSWORD
accept: application/json
Content-Type: application/json

{
  "allow_merge_commits": false,
  "allow_rebase": false,
  "allow_rebase_explicit": false,
  "allow_squash_merge": false,
  "archived": false,
  "default_branch": "master"
}

The answer I got from the request:

PATCH https://try.gitea.io/api/v1/repos/khmtestorga/testrepo

HTTP/1.1 200 OK
Content-Length: 1294
Content-Type: application/json; charset=UTF-8
Date: Wed, 18 Nov 2020 15:59:33 GMT
Set-Cookie: lang=en-US; Path=/; Max-Age=2147483647
Set-Cookie: i_like_gitea=d98defc8aa9674ca; Path=/; HttpOnly
Set-Cookie: _csrf=vSQjaJTg6nzcl5Lqkh4bLjFaoJI6MTYwNTcxNTE3Mjg2NTg1NDgyNg; Path=/; Expires=Thu, 19 Nov 2020 15:59:32 GMT; HttpOnly
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN

{
  "id": 21480,
  "owner": {
    "id": 42394,
    "login": "khmtestorga",
    "full_name": "",
    "email": "",
    "avatar_url": "https://try.gitea.io/user/avatar/khmtestorga/-1",
    "language": "",
    "is_admin": false,
    "last_login": "1970-01-01T00:00:00Z",
    "created": "2020-11-18T15:57:08Z",
    "username": "khmtestorga"
  },
  "name": "testrepo",
  "full_name": "khmtestorga/testrepo",
  "description": "",
  "empty": true,
  "private": false,
  "fork": false,
  "template": false,
  "parent": null,
  "mirror": false,
  "size": 17,
  "html_url": "https://try.gitea.io/khmtestorga/testrepo",
  "ssh_url": "git@try.gitea.io:khmtestorga/testrepo.git",
  "clone_url": "https://try.gitea.io/khmtestorga/testrepo.git",
  "original_url": "",
  "website": "",
  "stars_count": 0,
  "forks_count": 0,
  "watchers_count": 1,
  "open_issues_count": 0,
  "open_pr_counter": 0,
  "release_counter": 0,
  "default_branch": "master",
  "archived": false,
  "created_at": "2020-11-18T15:57:37Z",
  "updated_at": "2020-11-18T15:59:33Z",
  "permissions": {
    "admin": true,
    "push": true,
    "pull": true
  },
  "has_issues": true,
  "internal_tracker": {
    "enable_time_tracker": true,
    "allow_only_contributors_to_track_time": true,
    "enable_issue_dependencies": true
  },
  "has_wiki": true,
  "has_pull_requests": true,
  "has_projects": true,
  "ignore_whitespace_conflicts": false,
  "allow_merge_commits": true,
  "allow_rebase": true,
  "allow_rebase_explicit": true,
  "allow_squash_merge": true,
  "avatar_url": "",
  "internal": false
}

Response code: 200 (OK); Time: 967ms; Content length: 1294 bytes

So as you can see that the entries: allow_merge_commits, allow_rebase, allow_rebase_explicit and allow_squash_merge have not been changed at all.

Desription

The question is if I'm doing the change at the correct API endpoint or do I need to use a different one...

Activity

jolheiser

jolheiser commented on Nov 18, 2020

@jolheiser
Member

The issue here is the API is a little misleading.
On the Swagger page it states Edit a repository's properties. Only fields that are set will be changed.
However, when you view the model, all the PR-related changes have a small disclaimer has_pull_requests must be true

Basically, because you didn't specify "has_pull_requests": true the API skipped the PR-related values entirely. 🙃

if opts.HasPullRequests != nil {
if *opts.HasPullRequests && !models.UnitTypePullRequests.UnitGlobalDisabled() {
// We do allow setting individual PR settings through the API, so
// we get the config settings and then set them
// if those settings were provided in the opts.
unit, err := repo.GetUnit(models.UnitTypePullRequests)
var config *models.PullRequestsConfig
if err != nil {
// Unit type doesn't exist so we make a new config file with default values
config = &models.PullRequestsConfig{
IgnoreWhitespaceConflicts: false,
AllowMerge: true,
AllowRebase: true,
AllowRebaseMerge: true,
AllowSquash: true,
}
} else {
config = unit.PullRequestsConfig()
}
if opts.IgnoreWhitespaceConflicts != nil {
config.IgnoreWhitespaceConflicts = *opts.IgnoreWhitespaceConflicts
}
if opts.AllowMerge != nil {
config.AllowMerge = *opts.AllowMerge
}
if opts.AllowRebase != nil {
config.AllowRebase = *opts.AllowRebase
}
if opts.AllowRebaseMerge != nil {
config.AllowRebaseMerge = *opts.AllowRebaseMerge
}
if opts.AllowSquash != nil {
config.AllowSquash = *opts.AllowSquash
}
units = append(units, models.RepoUnit{
RepoID: repo.ID,
Type: models.UnitTypePullRequests,
Config: config,
})
} else if !*opts.HasPullRequests && !models.UnitTypePullRequests.UnitGlobalDisabled() {
deleteUnitTypes = append(deleteUnitTypes, models.UnitTypePullRequests)
}
}

I think this could be refactored to be easier to work with.


I'm going to close this issue and open a new one detailing the problem.

added
issue/not-a-bugThe reported issue is the intended behavior or the problem is not inside Gitea
and removed on Nov 18, 2020
khmarbaise

khmarbaise commented on Nov 18, 2020

@khmarbaise
MemberAuthor

Thanks for your reply and the solution with the details. I've checked that on try.gitea.io and simply it works. Great.

locked and limited conversation to collaborators on Jan 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue/not-a-bugThe reported issue is the intended behavior or the problem is not inside Giteamodifies/apiThis PR adds API routes or modifies them

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @khmarbaise@lunny@jolheiser

        Issue actions

          REST API PATCH Repository Configuration within Organisation · Issue #13620 · go-gitea/gitea