Skip to content

api: support getting repository Git tree (#5934)#5937

Merged
unknwon merged 9 commits intogogs:masterfrom
bharatnc:bnc/gogs-5934-git-tree-api
Feb 25, 2020
Merged

api: support getting repository Git tree (#5934)#5937
unknwon merged 9 commits intogogs:masterfrom
bharatnc:bnc/gogs-5934-git-tree-api

Conversation

@bharatnc
Copy link
Copy Markdown
Contributor

@bharatnc bharatnc commented Feb 24, 2020

This PR adds the tree api endpoint to gogs api:
GET/repos/:owner/:repo/git/trees/:tree_sha

This new api endpoint that is being added is in conformance to
the GitHub REST API v3 specification. Documentation can be found
here: developer.github.com/v3/git/trees/#get-a-tree

For a given user, repo and sha value, this api (currently) returns
a single tree using the SHA1 value for that tree.

  • Recursive implementation is yet to be implemented.
  • Creating a Tree using POST is yet to be implemented.

Example curl:


l curl -H "Authorization: token REDACTED" http://localhost:3000/api/v1/repos/root/testrepo/git/trees/c59441ded1549b149def0d4c54594d31a7f3718f -X GET  | jq .
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   940  100   940    0     0  12034      0 --:--:-- --:--:-- --:--:-- 12051

[
  {
    "sha": "c59441ded1549b149def0d4c54594d31a7f3718f",
    "tree": [
      {
        "mode": "120000",
        "path": "/home/bharatnc/gogs-repositories/root/testrepo.git",
        "sha": "472ac2361b65136b393d652de25341e2ea44f299",
        "size": 1077,
        "type": "blob",
        "url": "http://localhost:3000/api/v1/repos/root/testrepo/git/trees/472ac2361b65136b393d652de25341e2ea44f299"
      },
      {
        "mode": "120000",
        "path": "/home/bharatnc/gogs-repositories/root/testrepo.git",
        "sha": "70fcb456d436f08462602f26df6fb7e167e7a916",
        "size": 12,
        "type": "blob",
        "url": "http://localhost:3000/api/v1/repos/root/testrepo/git/trees/70fcb456d436f08462602f26df6fb7e167e7a916"
      },
      {
        "mode": "120000",
        "path": "/home/bharatnc/gogs-repositories/root/testrepo.git",
        "sha": "092c58d4b63df5779a4d020b1fdbb762421bbb4f",
        "size": 380,
        "type": "blob",
        "url": "http://localhost:3000/api/v1/repos/root/testrepo/git/trees/092c58d4b63df5779a4d020b1fdbb762421bbb4f"
      }
    ],
    "url": "http://localhost:3000/api/v1/repos/root/testrepo/git/trees/c59441ded1549b149def0d4c54594d31a7f3718f"
  }
]

@bharatnc
Copy link
Copy Markdown
Contributor Author

bharatnc commented Feb 24, 2020

@unknwon , I made some progress with respect to the trees api endpoint for gogs based on your inputs (#5934). Would appreciate feedback. Thank you!

@bharatnc bharatnc changed the title add basic git repository tree api (#5934) add basic git repository tree api (# 5934) Feb 24, 2020
@bharatnc bharatnc force-pushed the bnc/gogs-5934-git-tree-api branch from ee9452b to 7eba630 Compare February 24, 2020 07:48
Copy link
Copy Markdown
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.

Few questions unrelated to the core changes:

  1. I don't see you add the new import of golang.org/x/tools and githubo.com/modern-go/* anywhere in the diffs, why go.mod wants to include those?
  2. I don't see any changes to "public/", "templates/" directories and any "*.less" files, where does these changes come form?
  3. Which IDE you're using? The "internal/route/api/v1/repo/file.go" looks like is not gofmted, and it would more ideal to put in its own file, namely "tree.go".

@bharatnc bharatnc force-pushed the bnc/gogs-5934-git-tree-api branch 9 times, most recently from 61732bc to 1be5704 Compare February 25, 2020 05:42
@bharatnc
Copy link
Copy Markdown
Contributor Author

bharatnc commented Feb 25, 2020

@unknwon,

I don't see you add the new import of golang.org/x/tools and githubo.com/modern-go/* anywhere in the diffs, why go.mod wants to include those?

They should be gone now. Not sure what happened there.

I don't see any changes to "public/", "templates/" directories and any "*.less" files, where does these changes come form?

Yep, interesting, I have discarded changes to those files and updated the PR. In fact when I again ran make web, I could see that new files are generated - though there are no changes to the UI :(

rm -f internal/assets/public/public_gen.go
go generate internal/assets/public/public.go
gofmt -s -w internal/assets/public/public_gen.go

Which IDE you're using? The "internal/route/api/v1/repo/file.go" looks like is not gofmted, and it would more ideal to put in its own file, namely "tree.go".

I use GoLand by Jetbrains. But that shouldn't matter, I usually run gofmt -w <file> to ensure formatting. Only in this file it did not make any difference. I have made a few changes and formatted the file again so that it looks normal now.

Thank you for the feedback. I have also moved this new Tree method into it's own file called tree.go as per your suggestion. Please let me know if you would like me to do some other changes. Thank you!

@unknwon
Copy link
Copy Markdown
Member

unknwon commented Feb 25, 2020

I don't see you add the new import of golang.org/x/tools and githubo.com/modern-go/* anywhere in the diffs, why go.mod wants to include those?
They should be gone now. Not sure what happened there.

I don't see any changes to "public/", "templates/" directories and any "*.less" files, where does these changes come form?

I think it was my mistake that I didn't properly update these files on master, which I fixed yesterday, so no longer showing them on your PR.

@unknwon
Copy link
Copy Markdown
Member

unknwon commented Feb 25, 2020

i use GoLand by Jetbrains. But that shouldn't matter, I usually run gofmt -w <file> to ensure formatting. Only in this file it did not make any difference. I have made a few changes and formatted the file again so that it looks normal now.

GoLand sadly does not enable gofmt by default, here's how you could tell it to format:
image

@bharatnc
Copy link
Copy Markdown
Contributor Author

bharatnc commented Feb 25, 2020

I have also synced my fork with the master and have properly rebased my changes over it.

@bharatnc
Copy link
Copy Markdown
Contributor Author

i use GoLand by Jetbrains. But that shouldn't matter, I usually run gofmt -w <file> to ensure formatting. Only in this file it did not make any difference. I have made a few changes and formatted the file again so that it looks normal now.

GoLand sadly do not enable gofmt by default, here's how you could tell it to format:
image

Oh yea, I usually manually do Tools -> Go Tools -> Go fmt file

@unknwon unknwon linked an issue Feb 25, 2020 that may be closed by this pull request
@unknwon
Copy link
Copy Markdown
Member

unknwon commented Feb 25, 2020

PS: you don’t need/have to force push, we’re going to squash and merge anyway.

This PR adds the tree  api endpoint to gogs api:
`GET/repos/:owner/:repo/git/trees/:tree_sha`

This new api endpoint that is being added is in conformance to
the GitHub REST API v3 specification. Documentation can be found
here: developer.github.com/v3/git/trees/#get-a-tree

For a given user, repo and sha value, this api (currently) returns
a single tree using the SHA1 value for that tree.

- Recursive implementation is yet to be implemented.
- Creating a Tree using POST is yet to be implemented.

Example curl:

```

l curl -H "Authorization: token REDACTED" http://localhost:3000/api/v1/repos/root/testrepo/git/trees/c59441ded1549b149def0d4c54594d31a7f3718f -X GET  | jq .
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   940  100   940    0     0  12034      0 --:--:-- --:--:-- --:--:-- 12051

[
  {
    "sha": "c59441ded1549b149def0d4c54594d31a7f3718f",
    "tree": [
      {
        "mode": "120000",
        "path": "/home/bharatnc/gogs-repositories/root/testrepo.git",
        "sha": "472ac2361b65136b393d652de25341e2ea44f299",
        "size": 1077,
        "type": "blob",
        "url": "http://localhost:3000/api/v1/repos/root/testrepo/git/trees/472ac2361b65136b393d652de25341e2ea44f299"
      },
      {
        "mode": "120000",
        "path": "/home/bharatnc/gogs-repositories/root/testrepo.git",
        "sha": "70fcb456d436f08462602f26df6fb7e167e7a916",
        "size": 12,
        "type": "blob",
        "url": "http://localhost:3000/api/v1/repos/root/testrepo/git/trees/70fcb456d436f08462602f26df6fb7e167e7a916"
      },
      {
        "mode": "120000",
        "path": "/home/bharatnc/gogs-repositories/root/testrepo.git",
        "sha": "092c58d4b63df5779a4d020b1fdbb762421bbb4f",
        "size": 380,
        "type": "blob",
        "url": "http://localhost:3000/api/v1/repos/root/testrepo/git/trees/092c58d4b63df5779a4d020b1fdbb762421bbb4f"
      }
    ],
    "url": "http://localhost:3000/api/v1/repos/root/testrepo/git/trees/c59441ded1549b149def0d4c54594d31a7f3718f"
  }
]

```
@bharatnc bharatnc force-pushed the bnc/gogs-5934-git-tree-api branch from 1be5704 to aa658b6 Compare February 25, 2020 06:27
@bharatnc
Copy link
Copy Markdown
Contributor Author

PS: you don’t need/have to force push, we’re going to squash and merge anyway.

Noted - will maintain additional commits hereafter. I'm just used to maintaining a single commit (force pushing) on a daily basis :) .

@bharatnc bharatnc force-pushed the bnc/gogs-5934-git-tree-api branch from a0a8327 to d1ae62e Compare February 25, 2020 06:35
@bharatnc bharatnc force-pushed the bnc/gogs-5934-git-tree-api branch from d1ae62e to e8c8bee Compare February 25, 2020 06:37
@bharatnc bharatnc force-pushed the bnc/gogs-5934-git-tree-api branch 4 times, most recently from 0ae230d to c0a7788 Compare February 25, 2020 06:59
@bharatnc bharatnc force-pushed the bnc/gogs-5934-git-tree-api branch from c0a7788 to 2107f45 Compare February 25, 2020 07:00
@unknwon
Copy link
Copy Markdown
Member

unknwon commented Feb 25, 2020

FYI, I directly edited the file for some minor changes. Please see my comment above, that should be the last thing we need to address!

@bharatnc
Copy link
Copy Markdown
Contributor Author

FYI, I directly edited the file for some minor changes. Please see my comment above, that should be the last thing we need to address!

@unknwon thanks and I have addressed the last bit of the change that's required. I really appreciate the reviews!

@unknwon
Copy link
Copy Markdown
Member

unknwon commented Feb 25, 2020

Congrats, merging!

@unknwon unknwon removed the status: needs feedback Tell me more about it label Feb 25, 2020
@unknwon unknwon changed the title add basic git repository tree api (# 5934) api: support getting repository Git tree (#5934) Feb 25, 2020
@unknwon unknwon merged commit cf3d55f into gogs:master Feb 25, 2020
@bharatnc
Copy link
Copy Markdown
Contributor Author

@unknwon I can work on adding the docs for this new endpoint.

@unknwon
Copy link
Copy Markdown
Member

unknwon commented Feb 25, 2020

Great :)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 20, 2022
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.

API for listing Git repository tree

2 participants