Commit Graph

35 Commits (0a92ad27efa972d6e960665fd274eb765fbabcec)

Author SHA1 Message Date
Joe Chen 0a92ad27ef
db: use `context` and go-mockgen for `AccessTokensStore` (#7013) 2022-06-06 12:10:36 +08:00
Joe Chen 7885f454a4
webhook: revalidate local hostname before each delivery (#6988) 2022-05-31 15:17:17 +08:00
deepsource-autofix[bot] deec3516d5
autofix: fix check for empty string (#6804)
Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
2022-03-06 16:33:45 +08:00
Devops d60d9cf985
api: support listing repository tags (#6656)
Co-authored-by: zhouzhibo <zhouzhibo>
Co-authored-by: Joe Chen <jc@unknwon.io>
2021-12-14 20:41:12 +08:00
Pavel M de3161155b
api: EditWiki implementation (#5860)
Co-authored-by: Joe Chen <jc@unknwon.io>
2021-11-10 13:29:27 +08:00
Jordan Levin b9a3626cad
api: add `GET /api/v1/{owner}/{repo}/commits` endpoint (#6574)
This pull request targets issue #6573.

It provides a new API endpoint: `/api/v1/repos/{org}/{repo}/commits?pageSize=<int>` with a default page size of 30 commits (the same as the UI).

This implementation currently only focuses on the main/master branch of the repository, and does not provide the ability to return commit history for other branches.

- Note: Since the logic for converting a git.Commit to api.Commit had to be used in `GetAllCommits` and `GetSingleCommit`, I decided to pull the code out into a helper function, ` gitCommitToAPICommit(commit, context)`.
2021-09-24 00:33:52 +08:00
ᴜɴᴋɴᴡᴏɴ 1a1a01a842
ci: use new lint action and add custom config (#6562) 2021-05-19 13:38:13 +08:00
Atin d6987ee05b
chore: fix typos in code comments (#6556) 2021-05-19 13:12:09 +08:00
ᴜɴᴋɴᴡᴏɴ 2eaf1d693a
db: migrate access table to use GORM (#6371) 2020-10-06 15:43:28 +08:00
Kousik Mitra 5a52ee75e3
db: remove `db.User.LoginType` field (#6122) 2020-04-19 04:32:53 +08:00
ᴜɴᴋɴᴡᴏɴ 9d64d222a8
db: add tests for users (#6116)
* Add new methods

* Use Users.Create to replace previous hack

* Reduce side effect

* Do not clear tables when test failed

* test_users_Authenticate

* Rename constant

* test_users_Create

* test_users_GetByEmail

* test_users_GetByID

* test_users_GetByUsername
2020-04-18 12:07:30 +08:00
ᴜɴᴋɴᴡᴏɴ fa497b1633
db: add tests for repos (#6112)
* Add Repos.create method

* Fix repo name error handling

* Fix all compile errors

* Update github.com/go-macaron/captcha to fix http issue

* Add repos tests
2020-04-17 10:14:18 +08:00
Rui Santos 440b1ecbfd
api: add admin endpoint to get team members (#6101)
fixes #5877
2020-04-15 06:00:44 +08:00
ᴜɴᴋɴᴡᴏɴ 41f56ad05d
login_source: migrate to GORM and add tests (#6090)
* Use GORM in all write paths

* Migrate to GORM

* Fix lint errors

* Use GORM  to init table

* dbutil: make writer detect error

* Add more tests

* Rename to clearTables

* db: finish adding tests

* osutil: add tests

* Fix load source files path
2020-04-11 20:18:05 +08:00
ᴜɴᴋɴᴡᴏɴ 62dda96159
access_token: migrate to GORM and add tests (#6086)
* access_token: migrate to GORM

* Add tests

* Fix tests

* Fix test clock
2020-04-11 01:25:19 +08:00
ᴜɴᴋɴᴡᴏɴ 34145c990d
lfs: implement HTTP routes (#6035)
* Bootstrap with GORM

* Fix lint error

* Set conn max lifetime to one minute

* Fallback to use gorm v1

* Define HTTP routes

* Finish authentication

* Save token updated

* Add docstring

* Finish authorization

* serveBatch rundown

* Define types in lfsutil

* Finish Batch

* authutil

* Finish basic

* Formalize response error

* Fix lint errors

* authutil: add tests

* dbutil: add tests

* lfsutil: add tests

* strutil: add tests

* Formalize 401 response
2020-04-04 21:14:15 +08:00
Philidor Green 470274204e
api: support get releases endpoint (#6026) 2020-03-28 21:56:11 +08:00
ᴜɴᴋɴᴡᴏɴ 22717a1c06
webhook: overhaul route handlers (#6002)
* Overual route handlers and fixes #5366

* Merge routes for repo and org

* Inject OrgRepoContext

* DRY validateWebhook

* DRY c.HasError

* Add tests

* Update CHANGELOG
2020-03-22 22:07:22 +08:00
ᴜɴᴋɴᴡᴏɴ 9e9ca66467
refactor: unify error handling in routing layer 2020-03-16 01:22:27 +08:00
Bharat Nallan 268c692efd
api: group "/contents" with "" and "/*" #5985 (#5986)
This PR groups the contents api endpoint with both `""` and `/*` as
valid URL patterns.

When `""` is the URL pattern, this means that no repo path has'nt been
provided, in which case the path would be the default repo path.

When  `"/*"` is the URL pattern, then this would return the contents at
the specified path if it's valid.

Github API v3 is conformant to this behavior and have verified it
locally.
2020-03-13 22:37:42 +08:00
ᴜɴᴋɴᴡᴏɴ 927ffef864
api: minor changes to `/repo/owner/repo/git/trees` (#5982) 2020-03-11 01:28:26 +08:00
ᴜɴᴋɴᴡᴏɴ 880d0ec19f
api: overhaul `/repos/owner/repos/contents` (#5980)
* Fix import path renaming

* api: overhaul /repos/owner/repos/contents
2020-03-10 22:15:55 +08:00
ᴜɴᴋɴᴡᴏɴ 6437d0180b
git: migrate to github.com/gogs/git-module@v1.0.0 (#5958)
* WIP

* Finish `internal/db/git_diff.go`

* FInish internal/db/mirror.go

* Finish internal/db/pull.go

* Finish internal/db/release.go

* Finish internal/db/repo.go

* Finish internal/db/repo_branch.go

* Finish internal/db/repo_editor.go

* Finish internal/db/update.go

* Save my work

* Add license header

* Compile!

* Merge master

* Finish internal/cmd/hook.go

* Finish internal/conf/static.go

* Finish internal/context/repo.go

* Finish internal/db/action.go

* Finish internal/db/git_diff.go

* Fix submodule URL inferring

* Finish internal/db/mirror.go

* Updat to beta.4

* css: update fonts

* Finish internal/db/pull.go

* Finish internal/db/release.go

* Finish internal/db/repo_branch.go

* Finish internal/db/wiki.go

* gitutil: enhance infer submodule UR

* Finish internal/route/api/v1/repo/commits.go

* mirror: only collect branch commits after sync

* mirror: fix tag support

* Finish internal/db/repo.go

* Finish internal/db/repo_editor.go

* Finish internal/db/update.go

* Finish internal/gitutil/pull_request.go

* Make it compile

* Finish internal/route/repo/setting.go

* Finish internal/route/repo/branch.go

* Finish internal/route/api/v1/repo/file.go

* Finish internal/route/repo/download.go

* Finish internal/route/repo/editor.go

* Use helper

* Finish internal/route/repo/issue.go

* Finish internal/route/repo/pull.go

* Finish internal/route/repo/release.go

* Finish internal/route/repo/repo.go

* Finish internal/route/repo/wiki.go

* Finish internal/route/repo/commit.go

* Finish internal/route/repo/view.go

* Finish internal/gitutil/tag.go

* go.sum
2020-03-08 19:09:31 +08:00
ᴜɴᴋɴᴡᴏɴ 5ad2fdcf0b
api: `GET /repos/:owner/:repo/contents/:path` (#5963)
* support API `GET /repos/:owner/:repo/contents/:path`

This PR adds support to #5949:
`GET /repos/:owner/:repo/contents/:path`

Curl:

```bash
curl -H "Authorization: token REDACTED"
http://localhost:3000/api/v1/repos/root/testrepo/contents//master/README.md
-X GET  | jq .
```

Curl  Response:

```bash
{
  "type": "blob",
  "size": 12,
  "name": "README.md",
  "path": "README.md",
  "sha": "70fcb456d436f08462602f26df6fb7e167e7a916",
  "url": "http://localhost:3000/api/v1/repos/root/testrepo/contents/README.md",
  "git_url": "70fcb456d4",
  "html_url": "70fcb456d4",
  "download_url": "http://localhost:3000/api/v1/root/testrepo/raw/README.md",
  "_links": {
    "git": "70fcb456d4",
    "self": "http://localhost:3000/api/v1/repos/root/testrepo/contents/README.md",
    "html": "70fcb456d4"
  },
  "content": "IyB0ZXN0cmVwbwoK"
}

```

* rename - path.go to contents.go

* reorder imports

Co-Authored-By: ᴜɴᴋɴᴡᴏɴ <u@gogs.io>

* rename struct to repoContents and fix field order

Co-Authored-By: ᴜɴᴋɴᴡᴏɴ <u@gogs.io>

* rename variable

Co-Authored-By: ᴜɴᴋɴᴡᴏɴ <u@gogs.io>

* rename GetPathContents to GetContents

Co-Authored-By: ᴜɴᴋɴᴡᴏɴ <u@gogs.io>

* return on server error

Co-Authored-By: ᴜɴᴋɴᴡᴏɴ <u@gogs.io>

* resolve conflicts introduced via git web ui

* make constants as method variables

* handle dir type case last

* fix func and var names

* implement suggested changes in review

* refactor smaller funcs to be part of GetContent

* fix content type check for blob after refactoring

* changes based on suggestions

* read full file, return empty json array

* don't set submoduleURL

* set server err msg to method name

* set target to be blob data for symlinks

* Update contents.go

Co-authored-by: ᴜɴᴋɴᴡᴏɴ <u@gogs.io>
2020-03-05 16:15:38 +08:00
ᴜɴᴋɴᴡᴏɴ f04b2d4350
lint: fix some Golang CI lint issues (#5955) 2020-03-01 14:55:03 +08:00
ᴜɴᴋɴᴡᴏɴ 7950f2d17d
conf: overhaul auth and user settings (#5942)
* conf: overhaul auth and user settings

* ci: update travis Go versions
2020-02-27 18:06:38 +08:00
Bharat Nallan cf3d55fa10
api: support getting repository Git tree (#5934) (#5937)
* add basic git repository tree api (#5934)

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" c59441ded1 -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": "472ac2361b"
      },
      {
        "mode": "120000",
        "path": "/home/bharatnc/gogs-repositories/root/testrepo.git",
        "sha": "70fcb456d436f08462602f26df6fb7e167e7a916",
        "size": 12,
        "type": "blob",
        "url": "70fcb456d4"
      },
      {
        "mode": "120000",
        "path": "/home/bharatnc/gogs-repositories/root/testrepo.git",
        "sha": "092c58d4b63df5779a4d020b1fdbb762421bbb4f",
        "size": 380,
        "type": "blob",
        "url": "092c58d4b6"
      }
    ],
    "url": "c59441ded1"
  }
]

```

* remove vertical space

* make go.mod to be same as in master

* rename structs to sound better

* simplify expressions and fix error msg

* Update tree.go

* Update tree.go

* display file name instead of repo path

* Update tree.go

Co-authored-by: ᴜɴᴋɴᴡᴏɴ <u@gogs.io>
2020-02-25 22:19:42 +08:00
ᴜɴᴋɴᴡᴏɴ 52ffb67b33
conf: overhaul email settings (#5940) 2020-02-25 00:35:35 +08:00
ᴜɴᴋɴᴡᴏɴ 648d9e253c
conf: overhaul server settings (#5928)
* conf: rename package

* Requires Go 1.12

* Fix lint

* Fix lint

* Overhaul

* db: fix tests

* Save my work

* Fix tests

* Server.UnixSocketPermission

* Server.LocalRootURL

* SSH settings

* Server.OfflineMode

* Save my work

* App.Version

* Remove [server] STATIC_ROOT_PATH

* Server.LandingURL
2020-02-22 09:05:26 +08:00
ᴜɴᴋɴᴡᴏɴ 1c09373b4f
log: migrate to unknwon.dev/clog/v2 (#5927)
* Add unknwon.dev/clog/v2

* Update all places
2020-02-20 02:25:02 +08:00
ᴜɴᴋɴᴡᴏɴ 2f4cc5480e
api/misc/markdown: remove Mode option (#5910)
We already have a separate `/markdown/raw` API, remove redundant functionality here.
2020-01-29 02:41:31 +08:00
ᴜɴᴋɴᴡᴏɴ 5e6c3b9d0e
api: sanitize raw markdown content (#5907)
Fixed a security issue reported by bluebird.
2020-01-27 00:18:46 +08:00
Yoan Blanc 76b87b1bbd repo: use editorconfig v2 (#5888)
* repo: editorconfig v2

Signed-off-by: Yoan Blanc <yoan@dosimple.ch>

* fixup! repo: editorconfig v2

Signed-off-by: Yoan Blanc <yoan@dosimple.ch>

* Update repo.go

* Update repo.go

Co-authored-by: Unknwon <u@gogs.io>
2019-12-25 10:26:57 +08:00
Unknwon 390b903c55
web: fix panic when download attachments (#5838) 2019-10-24 19:58:30 -07:00
Unknwon 01c8df01ec
internal: move packages under this directory (#5836)
* Rename pkg -> internal

* Rename routes -> route

* Move route -> internal/route

* Rename models -> db

* Move db -> internal/db

* Fix route2 -> route

* Move cmd -> internal/cmd

* Bump version
2019-10-24 01:51:46 -07:00