diff --git a/.crystal-version b/.crystal-version index 85e60ed..ca71766 100644 --- a/.crystal-version +++ b/.crystal-version @@ -1 +1 @@ -0.34.0 +1.11.2 diff --git a/Dockerfile b/Dockerfile index 8602b48..9f9ea0d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM crystallang/crystal:0.34.0-alpine-build AS build-env +FROM crystallang/crystal:1.11.2-alpine-build AS build-env RUN apk --no-cache add build-base libgit2 git nodejs yarn libgit2-dev @@ -15,7 +15,7 @@ RUN yarn prod RUN lucky build.release -FROM crystallang/crystal:0.34.0-alpine-build +FROM crystallang/crystal:1.11.2-alpine-build RUN mkdir -p /app WORKDIR /app diff --git a/README.md b/README.md index 2b2427c..656ad21 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ Microgit is meant to be a self-hosting open source that will be an alternative to gitlab. See this as a crystal version of gitea but with own design. +This project now targets Crystal `1.11.2`. + ## What it can do now: * Git pull/push/fetch * See tree of files diff --git a/shard.lock b/shard.lock index 8ba9d9f..6128d03 100644 --- a/shard.lock +++ b/shard.lock @@ -1,146 +1,182 @@ -version: 1.0 +version: 2.0 shards: apatite: - github: watzon/apatite - commit: 9ed28220eb7136eecc05c70cb16b7a41a6d0e958 + git: https://github.com/watzon/apatite.git + version: 0.1.0+git.commit.36f3aef41e31b75e824b9b60ec30cdc399ced9c9 authentic: - github: luckyframework/authentic - version: 0.5.4 + git: https://github.com/luckyframework/authentic.git + version: 1.0.2 avram: - github: luckyframework/avram - version: 0.14.0 + git: https://github.com/luckyframework/avram.git + version: 1.3.0 - avram_scoped_id: - github: microgit-com/avram_scoped_id - commit: d5853177e55fabc04c9456f5b45f073e3f5a54d9 + backtracer: + git: https://github.com/sija/backtracer.cr.git + version: 1.2.4 - blank: - github: kostya/blank - version: 0.1.0 + bindata: + git: https://github.com/spider-gazelle/bindata.git + version: 2.1.0 cadmium_classifier: - github: cadmiumcr/classifier - commit: 22609f050564fb90595bdbdfdf4007e67861c5c4 + git: https://github.com/cadmiumcr/classifier.git + version: 0.2.0+git.commit.9ac9abe0ba882ccc085bde732f16e79e186d83e3 cadmium_tokenizer: - github: cadmiumcr/tokenizer - commit: e7f8733e4d8ead9a811b6f41d0b5fa621ba03033 + git: https://github.com/cadmiumcr/tokenizer.git + version: 0.1.0+git.commit.e7f8733e4d8ead9a811b6f41d0b5fa621ba03033 + + cadmium_transliterator: + git: https://github.com/cadmiumcr/transliterator.git + version: 0.1.0+git.commit.46c4c14594057dbcfaf27e7e7c8c164d3f0ce3f1 carbon: - github: luckyframework/carbon - version: 0.1.1 + git: https://github.com/luckyframework/carbon.git + version: 0.6.0 cry: - github: paulcsmith/cry - version: 0.4.2 + git: https://github.com/luckyframework/cry.git + version: 0.4.3 + + crystar: + git: https://github.com/naqvis/crystar.git + version: 0.3.1 db: - github: crystal-lang/crystal-db - version: 0.9.0 + git: https://github.com/crystal-lang/crystal-db.git + version: 0.13.1 dexter: - github: luckyframework/dexter - version: 0.2.0 + git: https://github.com/luckyframework/dexter.git + version: 0.3.4 dotenv: - github: gdotdesign/cr-dotenv + git: https://github.com/gdotdesign/cr-dotenv.git version: 0.3.0 exception_page: - github: crystal-loot/exception_page - version: 0.1.4 + git: https://github.com/crystal-loot/exception_page.git + version: 0.5.0 + + fnv: + git: https://github.com/naqvis/crystal-fnv.git + version: 0.1.3 git: - github: microgit-com/libgit2.cr - commit: 7069411d3357628a6294af97f88e9c718e87f8e9 + git: https://github.com/microgit-com/libgit2.cr.git + version: 0.1.0+git.commit.7069411d3357628a6294af97f88e9c718e87f8e9 git_diff_parser: - github: microgit-com/git_diff_parser - commit: e9e7db8e14367680a8478cfcb569f6ff6c33e531 + git: https://github.com/microgit-com/git_diff_parser.git + version: 0.1.0+git.commit.e9e7db8e14367680a8478cfcb569f6ff6c33e531 habitat: - github: luckyframework/habitat - version: 0.4.3 + git: https://github.com/luckyframework/habitat.git + version: 0.4.9 + + html5: + git: https://github.com/naqvis/crystal-html5.git + version: 0.5.0 jwt: - github: crystal-community/jwt - version: 1.2.0 + git: https://github.com/crystal-community/jwt.git + version: 1.6.1 kilt: - github: jeromegn/kilt - version: 0.6.0 + git: https://github.com/jeromegn/kilt.git + version: 0.6.1 linguist: - github: microgit-com/linguist.cr + git: https://github.com/microgit-com/linguist.cr.git version: 0.2.2 lucky: - github: luckyframework/lucky - version: 0.21.1 + git: https://github.com/luckyframework/lucky.git + version: 1.3.0 - lucky_can: - github: confact/lucky_can - commit: 2004fe0e4d02a43ca3f7b4728c28b1c501285a9c + lucky_cache: + git: https://github.com/luckyframework/lucky_cache.git + version: 0.1.1 - lucky_cli: - github: luckyframework/lucky_cli - version: 0.21.0 + lucky_can: + git: https://github.com/confact/lucky_can.git + version: 0.1.0+git.commit.2004fe0e4d02a43ca3f7b4728c28b1c501285a9c lucky_encrypted: - github: microgit-com/lucky_encrypted - commit: 7f8f8ae16b4801d9237cc75044f915d1ea67f323 + git: https://github.com/microgit-com/lucky_encrypted.git + version: 0.5.0+git.commit.87ff7a96b5d1eb36dd129ffde12b34c6c295980c lucky_flow: - github: luckyframework/lucky_flow - version: 0.6.3 + git: https://github.com/luckyframework/lucky_flow.git + version: 0.10.0 lucky_router: - github: luckyframework/lucky_router - version: 0.2.2 + git: https://github.com/luckyframework/lucky_router.git + version: 0.6.0 - markd: - github: icyleaf/markd + lucky_task: + git: https://github.com/luckyframework/lucky_task.git + version: 0.3.0 + + lucky_template: + git: https://github.com/luckyframework/lucky_template.git version: 0.2.0 + markd: + git: https://github.com/icyleaf/markd.git + version: 0.5.0 + mosquito: - github: robacarp/mosquito - version: 0.7.0 + git: https://github.com/robacarp/mosquito.git + version: 2.0.0 openssl_ext: - github: stakach/openssl_ext - version: 1.2.0 + git: https://github.com/spider-gazelle/openssl_ext.git + version: 2.4.4 pg: - github: will/crystal-pg - version: 0.21.0 + git: https://github.com/will/crystal-pg.git + version: 0.28.0 - pool: - github: ysbaddaden/pool + pulsar: + git: https://github.com/luckyframework/pulsar.git version: 0.2.3 redis: - github: stefanwille/crystal-redis - version: 2.6.0 + git: https://github.com/jgaskins/redis.git + version: 0.12.0 selenium: - github: ysbaddaden/selenium-webdriver-crystal - commit: bda2fd406c1a118251c5a2883f1e1f3af242116e + git: https://github.com/crystal-loot/selenium.cr.git + version: 0.12.1 shell-table: - github: luckyframework/shell-table.cr - commit: 078a04ea58ead5203bb435a3b5fff448ddabaeea + git: https://github.com/luckyframework/shell-table.cr.git + version: 0.9.3 sluggr: - github: microgit-com/sluggr - commit: 789ba497be050135465e8ef12b9b969514c5d2fd + git: https://github.com/microgit-com/sluggr.git + version: 0.1.0+git.commit.789ba497be050135465e8ef12b9b969514c5d2fd - teeplate: - github: luckyframework/teeplate - version: 0.8.1 + splay_tree_map: + git: https://github.com/wyhaines/splay_tree_map.cr.git + version: 0.3.0 + + webdrivers: + git: https://github.com/crystal-loot/webdrivers.cr.git + version: 0.4.4 + + webless: + git: https://github.com/crystal-loot/webless.git + version: 0.1.0 wordsmith: - github: luckyframework/wordsmith - version: 0.2.0 + git: https://github.com/luckyframework/wordsmith.git + version: 0.4.0 + + xpath2: + git: https://github.com/naqvis/crystal-xpath2.git + version: 0.1.3 diff --git a/shard.yml b/shard.yml index 66204a0..abf7ee1 100644 --- a/shard.yml +++ b/shard.yml @@ -8,27 +8,30 @@ targets: microgit: main: src/microgit.cr -crystal: 0.34.0 +crystal: 1.11.2 dependencies: lucky: github: luckyframework/lucky - version: ~> 0.21 + version: ~> 1.3 authentic: github: luckyframework/authentic - version: ~> 0.5.4 + version: ~> 1.0 carbon: github: luckyframework/carbon - version: ~> 0.1.1 + version: ~> 0.6 dotenv: github: gdotdesign/cr-dotenv version: 0.3.0 lucky_flow: github: luckyframework/lucky_flow - version: ~> 0.6.3 + version: ~> 0.10 jwt: github: crystal-community/jwt - version: ~> 1.2.0 + version: ~> 1.6 + avram: + github: luckyframework/avram + version: ~> 1.3 git: github: microgit-com/libgit2.cr kilt: @@ -39,16 +42,15 @@ dependencies: github: microgit-com/sluggr lucky_encrypted: github: microgit-com/lucky_encrypted + branch: master git_diff_parser: github: microgit-com/git_diff_parser linguist: github: microgit-com/linguist.cr redis: - github: stefanwille/crystal-redis - version: ~> 2.6 + github: jgaskins/redis + version: ~> 0.12 lucky_can: github: confact/lucky_can - avram_scoped_id: - github: microgit-com/avram_scoped_id mosquito: github: robacarp/mosquito diff --git a/src/handlers/git_handler.cr b/src/handlers/git_handler.cr index aa1e81b..612d2ac 100644 --- a/src/handlers/git_handler.cr +++ b/src/handlers/git_handler.cr @@ -70,8 +70,8 @@ class HTTP::GitHandler end private def clear_cache(repo) - redis = Redis::PooledClient.new - keys = redis.keys("#{repo.cache_key}*").map(&.to_s) + redis = Redis::Client.new + keys = redis.keys("#{repo.cache_key}*") return if keys.empty? redis.del(keys) end diff --git a/src/models/label.cr b/src/models/label.cr index e91794b..c18cd00 100644 --- a/src/models/label.cr +++ b/src/models/label.cr @@ -4,7 +4,7 @@ class Label < BaseModel column color : String belongs_to repository : Repository has_many label_in_items : LabelInItem - has_many issues : Issue, through: :label_in_items - has_many merge_requests : MergeRequest, through: :label_in_items + has_many issues : Issue, through: [:label_in_items, :issue] + has_many merge_requests : MergeRequest, through: [:label_in_items, :merge_request] end end diff --git a/src/models/team.cr b/src/models/team.cr index 7b401ac..f848df2 100644 --- a/src/models/team.cr +++ b/src/models/team.cr @@ -5,7 +5,7 @@ class Team < BaseModel has_one namespace : Namespace has_many repositories : Repository has_many team_members : TeamMembers - has_many users : User, through: :team_members + has_many users : User, through: [:team_members, :user] end def slug diff --git a/src/models/user.cr b/src/models/user.cr index 85e4eb3..fb27977 100644 --- a/src/models/user.cr +++ b/src/models/user.cr @@ -11,7 +11,7 @@ class User < BaseModel has_one namespace : Namespace has_many api_tokens : ApiToken has_many team_members : TeamMembers - has_many teams : Team, through: :team_members + has_many teams : Team, through: [:team_members, :team] end def confirmed? diff --git a/src/operations/create_issue.cr b/src/operations/create_issue.cr index 95ccfab..188fac1 100644 --- a/src/operations/create_issue.cr +++ b/src/operations/create_issue.cr @@ -4,7 +4,7 @@ class CreateIssue < Issue::SaveOperation needs repo_id : Int64 before_save do - AvramScopedId.set column: scoped_id, + ScopedId.set column: scoped_id, query: IssueQuery.new.repository_id(repo_id.not_nil!) end end diff --git a/src/operations/create_merge_request.cr b/src/operations/create_merge_request.cr index d51f3d4..77a6d4f 100644 --- a/src/operations/create_merge_request.cr +++ b/src/operations/create_merge_request.cr @@ -4,7 +4,7 @@ class CreateMergeRequest < MergeRequest::SaveOperation needs repo_id : Int64 before_save do - AvramScopedId.set column: scoped_id, + ScopedId.set column: scoped_id, query: MergeRequestQuery.new.repository_id(repo_id.not_nil!) end end diff --git a/src/scoped_id.cr b/src/scoped_id.cr new file mode 100644 index 0000000..a68194a --- /dev/null +++ b/src/scoped_id.cr @@ -0,0 +1,15 @@ +module ScopedId + extend self + + def set(column : Avram::Attribute(Int64 | Nil), query : Avram::Queryable) : Nil + set(column, query) + end + + macro set(column, query) + return unless {{column}}.value.nil? + scope = {{query.id}}.{{column.id}}.select_max + current_max_scoped_id = scope || 0 + id = current_max_scoped_id + 1 + {{column.id}}.value = id.to_i64 + end +end diff --git a/src/services/mixins/caching.cr b/src/services/mixins/caching.cr index e4eb36e..abfc3b8 100644 --- a/src/services/mixins/caching.cr +++ b/src/services/mixins/caching.cr @@ -1,10 +1,10 @@ module Caching private def caching(key, &block) - redis = Redis::PooledClient.new(pool_size: 5) + redis = Redis::Client.new cached = redis.get("#{@repo.cache_key}/#{key.downcase}") return cached unless cached.nil? data = yield redis.set("#{@repo.cache_key}/#{key.downcase}", data) - return data + data end end diff --git a/src/shards.cr b/src/shards.cr index 4102e59..db0c9c8 100644 --- a/src/shards.cr +++ b/src/shards.cr @@ -4,7 +4,7 @@ Dotenv.load # Require your shards here require "avram" -require "avram_scoped_id" +require "./scoped_id" require "lucky" require "carbon" require "authentic"