Skip to content

api: support put content#7114

Merged
unknwon merged 6 commits intogogs:mainfrom
smoorg:5967-put-contents
Oct 22, 2022
Merged

api: support put content#7114
unknwon merged 6 commits intogogs:mainfrom
smoorg:5967-put-contents

Conversation

@smoorg
Copy link
Contributor

@smoorg smoorg commented Jul 26, 2022

Describe the pull request

This pull request tries to close #5967 and add PUT content endpoint to gogs.

Maybe some things should be moved along and added to git-gogs-client package instead. I wasn't sure where to put types I needed during that development.

I do need someone to help me figure out how to properly add missing values. This is what I found on github API reference and I tried to follow it but had hard time figure out how to populate things like content's url, html_url, git_url, download_url and so on. I also couldn't figure out commit object's node_id, tree, parents. Let me know if there's any existing logic I could use to get those based on say git commit.

{
  "content": {
    "name": "hello.txt",
    "path": "notes/hello.txt",
    "sha": "95b966ae1c166bd92f8ae7d1c313e738c731dfc3",
    "size": 9,
    "url": "https://api.github.com/repos/octocat/Hello-World/contents/notes/hello.txt",
    "html_url": "https://github.com/octocat/Hello-World/blob/master/notes/hello.txt",
    "git_url": "https://api.github.com/repos/octocat/Hello-World/git/blobs/95b966ae1c166bd92f8ae7d1c313e738c731dfc3",
    "download_url": "https://raw.githubusercontent.com/octocat/HelloWorld/master/notes/hello.txt",
    "type": "file",
    "_links": {
      "self": "https://api.github.com/repos/octocat/Hello-World/contents/notes/hello.txt",
      "git": "https://api.github.com/repos/octocat/Hello-World/git/blobs/95b966ae1c166bd92f8ae7d1c313e738c731dfc3",
      "html": "https://github.com/octocat/Hello-World/blob/master/notes/hello.txt"
    }
  },
  "commit": {
    "sha": "7638417db6d59f3c431d3e1f261cc637155684cd",
    "node_id": "MDY6Q29tbWl0NzYzODQxN2RiNmQ1OWYzYzQzMWQzZTFmMjYxY2M2MzcxNTU2ODRjZA==",
    "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/7638417db6d59f3c431d3e1f261cc637155684cd",
    "html_url": "https://github.com/octocat/Hello-World/git/commit/7638417db6d59f3c431d3e1f261cc637155684cd",
    "author": {
      "date": "2014-11-07T22:01:45Z",
      "name": "Monalisa Octocat",
      "email": "octocat@github.com"
    },
    "committer": {
      "date": "2014-11-07T22:01:45Z",
      "name": "Monalisa Octocat",
      "email": "octocat@github.com"
    },
    "message": "my commit message",
    "tree": {
      "url": "https://api.github.com/repos/octocat/Hello-World/git/trees/691272480426f78a0138979dd3ce63b77f706feb",
      "sha": "691272480426f78a0138979dd3ce63b77f706feb"
    },
    "parents": [
      {
        "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/1acc419d4d6a9ce985db7be48c6349a0475975b5",
        "html_url": "https://github.com/octocat/Hello-World/git/commit/1acc419d4d6a9ce985db7be48c6349a0475975b5",
        "sha": "1acc419d4d6a9ce985db7be48c6349a0475975b5"
      }
    ],
    "verification": {
      "verified": false,
      "reason": "unsigned",
      "signature": null,
      "payload": null
    }
  }
}

Link to the issue: #5967

TODO:

  • add put endpoint
  • add provided base64 file to a commit
  • address possibility of empty author/commiter (logged user is author/commiter in such case)
  • return all the data related to content and commit along with HTTP 200

PS. This is my first PR in open source community so, well hi!

Checklist

  • I agree to follow the Code of Conduct by submitting this pull request.
  • I have read and acknowledge the Contributing guide.
  • I have added test cases to cover the new code.

smoorg added 3 commits July 26, 2022 12:28
Changes related to suggestions made by deepsource.io such as codestyle,
depreciated code used and anti-patterns.
@reiy-leo
Copy link

reiy-leo commented Oct 15, 2022

will the PUT api be available soon?

@unknwon unknwon self-requested a review October 22, 2022 14:15
@unknwon unknwon self-assigned this Oct 22, 2022
@codecov
Copy link

codecov bot commented Oct 22, 2022

Codecov Report

Merging #7114 (3faed62) into main (a5d3e19) will increase coverage by 0.16%.
The diff coverage is n/a.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7114      +/-   ##
==========================================
+ Coverage   11.76%   11.92%   +0.16%     
==========================================
  Files         106      107       +1     
  Lines       13619    13635      +16     
==========================================
+ Hits         1602     1626      +24     
+ Misses      11812    11799      -13     
- Partials      205      210       +5     

Copy link
Member

@unknwon unknwon left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

I push few commits to make this PR actually work, in a minimal sense. Then we can iterate from here.

@unknwon unknwon merged commit 742bc36 into gogs:main Oct 22, 2022
@smoorg smoorg deleted the 5967-put-contents branch March 30, 2023 22:09
dna2github pushed a commit to dna2fork/gogs that referenced this pull request May 1, 2023
Co-authored-by: Joe Chen <jc@unknwon.io>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support API: PUT /repos/:owner/:repo/contents/:path

3 participants