Skip to content

Commit

Permalink
Merge pull request #1669 from tryzealot/feat/update-app-build-api
Browse files Browse the repository at this point in the history
[API] add edit, destroy build of app
  • Loading branch information
icyleaf authored Sep 26, 2024
2 parents 8cd2b89 + 1acd74c commit f2ddae5
Show file tree
Hide file tree
Showing 18 changed files with 830 additions and 215 deletions.
31 changes: 31 additions & 0 deletions app/controllers/api/releases_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

class Api::ReleasesController < Api::BaseController
before_action :validate_user_token
before_action :set_release

# UPDATE /releases/:id
def update
@release.update!(release_params)
render json: @release
end

# DELETE /releases/:id
def destroy
@release.destroy
render json: { mesage: 'OK' }
end

protected

def set_release
@release = Release.find(params[:id])
end

def release_params
params.permit(
:release_version, :build_version, :release_type, :source, :branch, :git_commit,
:ci_url, :custom_fields, :changelog
)
end
end
6 changes: 3 additions & 3 deletions app/models/release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class Release < ApplicationRecord
has_one :metadata, class_name: 'Metadatum', dependent: :destroy
has_and_belongs_to_many :devices, dependent: :destroy

validates :file, presence: true
validates :file, presence: true, on: :create
validate :bundle_id_matched, on: :create
validate :determine_file_exist
validate :determine_disk_space
validate :determine_file_exist, on: :create
validate :determine_disk_space, on: :create

before_create :auto_release_version
before_create :default_source
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/release_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class ReleaseSerializer < ApplicationSerializer
attributes :version, :app_name, :bundle_id, :release_version, :build_version,
attributes :id, :version, :app_name, :bundle_id, :release_version, :build_version,
:source, :branch, :git_commit, :ci_url, :size, :platform, :device_type,
:icon_url, :install_url, :changelog, :text_changelog, :custom_fields,
:created_at
Expand Down
31 changes: 31 additions & 0 deletions config/locales/zealot/api.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@ en:
bundle_id: identifier valid check, set `*` skip (`bundle_id` for iOS, `package name` for Android)
git_url: Git repository URL
password: Enable password visit
release_options:
description: App's build metadata form data
properties:
build_version: Build version
release_version: Release version
source: the source of upload (default is `api`)
changelog: Change log, accept plain text or JSON formatted data
branch: a branch name from source control tool
git_commit: Git Commit SHA value
ci_url: the build url of a CI service
custom_fields: JSON formatted custom fields, icon only accepts fontawesome.
collaborator_options:
description: App's collaborator form data
properties:
Expand All @@ -144,6 +155,7 @@ en:
file: Zip arichved file (dSYM or Proguard)
release_version: Release version (requires if Android's Proguard file)
build_version: Build version (requires if Android's Proguard file)

apps:
default:
tags: Apps
Expand Down Expand Up @@ -185,6 +197,7 @@ en:
destroy:
title: Destroy an App
description: Destroy an App all data by ID, include schemes, channel, builds, debug files and the other related resources.

schemes:
default:
tags: Schemes
Expand All @@ -206,6 +219,7 @@ en:
destroy:
title: Destroy a scheme
description: Destroy a scheme from the App

channels:
default:
tags: Channel
Expand All @@ -227,6 +241,20 @@ en:
destroy:
title: Destroy a channel
description: Destroy a scheme's channel

releases:
default:
tags: Release
responses:
update: Update a build
destroy: Destroy build
update:
title: Update a build metedata
description: Update a build of app verison, custom_fileds, changelog etc
destroy:
title: Destroy a build
description: Destroy a app's build

collaborators:
default:
tags: Collaborators
Expand All @@ -248,6 +276,7 @@ en:
destroy:
title: Remove a collaborator from an App
description: Remove a collaborator from an App

debug_files:
default:
tags: Debug files
Expand Down Expand Up @@ -285,6 +314,7 @@ en:
destroy:
title: Destroy a debug file
description: Destroy a debug file ID and all data, include dSYM or Proguard files.

users:
default:
tags: Users
Expand Down Expand Up @@ -321,6 +351,7 @@ en:
unlock:
title: Unlock a user
description: Unlock a user to enable log in

version:
default:
tags: Version
Expand Down
25 changes: 25 additions & 0 deletions config/locales/zealot/api.zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ zh-CN:
bundle_id: 包名校验, 默认是 `*` 不做校验 (iOS 指的是 bundle_id,Android 指的是 package name)
git_url: Git 仓库地址
password: 密码访问
release_options:
description: 应用版本元信息表单字段结构
properties:
build_version: 构建版本
release_version: 发布版本
release_type: 应用类型,比如 debug, beta, adhoc, release, enterprise 等
source: 上传渠道名称,默认是 `api`
changelog: 变更日志,接受纯文本或 JSON 格式化的数据
branch: 代码控制软件的分支名
git_commit: 代码控制软件提交哈希值
ci_url: 持续构建系统构建 URL
custom_fields: 这是一个用 JSON 字符串定义的自定义字段,图标可接受 fontawesome
collaborator_options:
description: 应用成员表单字段结构
properties:
Expand Down Expand Up @@ -228,6 +240,19 @@ zh-CN:
title: 删除应用渠道
description: 从应用中删除指定应用渠道

releases:
default:
tags: 应用版本
responses:
update: 更新应用版本
destroy: 删除应用版本
update:
title: 更新应用版本元信息
description: 更新应用版本的版本、自定义字段、变更日志等信息
destroy:
title: 删除应用版本
description: 删除应用版本

collaborators:
default:
tags: 应用成员
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@

resources :collaborators, param: :user_id, except: %i[index new edit]
end
resources :releases, only: %i[update destroy]

resources :debug_files, except: %i[new edit create] do
collection do
Expand Down
10 changes: 8 additions & 2 deletions lib/tasks/zealot/zealot.rake
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,17 @@ namespace :zealot do
task :swaggerize do
ENV['RAILS_ENV'] = 'test'
current_locale = ENV['DEFAULT_LOCALE']

Rails.configuration.i18n.available_locales.each do |locale|
# reset task invoke status and execute
Rake::Task['rswag:specs:swaggerize'].reenable

puts "Generating swagger file ... #{locale}"
ENV['DEFAULT_LOCALE'] = current_locale.to_s
puts "Generating #{locale} swagger ..."
Rake::Task['rswag'].invoke
Rake::Task['rswag:specs:swaggerize'].invoke
end

# restore
ENV['DEFAULT_LOCALE'] = current_locale
ENV.delete('RAILS_ENV')
end
Expand Down
4 changes: 2 additions & 2 deletions spec/api/apps_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
description I18n.t('api.apps.create.description')
operationId 'createApp'

include_examples :request_form_body, '#/definitions/AppOptions'
include_examples :request_body, '#/definitions/AppOptions'

produces 'application/json'
response 201, I18n.t('api.apps.default.responses.show') do
Expand All @@ -148,7 +148,7 @@
operationId 'updateApp'

include_examples :primary_key_parameter
include_examples :request_form_body, '#/definitions/AppOptions'
include_examples :request_body, '#/definitions/AppOptions'

produces 'application/json'
response 200, I18n.t('api.apps.default.responses.show') do
Expand Down
4 changes: 2 additions & 2 deletions spec/api/channels_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
operationId 'createChannel'

include_examples :primary_key_parameter, :scheme_id
include_examples :request_form_body, '#/definitions/ChannelOptions'
include_examples :request_body, '#/definitions/ChannelOptions'

produces 'application/json'
response 201, I18n.t('api.channels.default.responses.create') do
Expand All @@ -49,7 +49,7 @@
operationId 'updateChannel'

include_examples :primary_key_parameter
include_examples :request_form_body, '#/definitions/ChannelOptions'
include_examples :request_body, '#/definitions/ChannelOptions'

produces 'application/json'
response 200, I18n.t('api.channels.default.responses.update') do
Expand Down
4 changes: 2 additions & 2 deletions spec/api/collaborators_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

include_examples :primary_key_parameter, :app_id
include_examples :primary_key_parameter, :user_id
include_examples :request_form_body, '#/definitions/CollaboratorOptions'
include_examples :request_body, '#/definitions/CollaboratorOptions'

produces 'application/json'
response 201, I18n.t('api.collaborators.default.responses.create') do
Expand All @@ -52,7 +52,7 @@

include_examples :primary_key_parameter, :app_id
include_examples :primary_key_parameter, :user_id
include_examples :request_form_body, '#/definitions/CollaboratorOptions'
include_examples :request_body, '#/definitions/CollaboratorOptions'

produces 'application/json'
response 200, I18n.t('api.collaborators.default.responses.update') do
Expand Down
44 changes: 44 additions & 0 deletions spec/api/releases_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: true

require 'swagger_helper'

RSpec.describe 'Releases API' do
path '/releases/{id}' do
put I18n.t('api.releases.update.title') do
tags I18n.t('api.releases.default.tags')
description I18n.t('api.releases.update.description')
operationId 'updateRelease'

include_examples :primary_key_parameter
include_examples :request_body, '#/definitions/ReleaseOptions'

produces 'application/json'
response 200, I18n.t('api.releases.default.responses.show') do
schema '$ref': '#/components/schemas/Release'
run_test!
end

include_examples :unauthorized_response
include_examples :not_found_response
end
end

path '/releases/{id}' do
delete I18n.t('api.releases.destroy.title') do
tags I18n.t('api.releases.default.tags')
description I18n.t('api.releases.destroy.description')
operationId 'destroyRelease'

include_examples :primary_key_parameter

produces 'application/json'
response 200, I18n.t('api.releases.default.responses.destroy') do
schema '$ref': '#/components/responses/Destroyed'
run_test!
end

include_examples :unauthorized_response
include_examples :not_found_response
end
end
end
4 changes: 2 additions & 2 deletions spec/api/schemes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
operationId 'createScheme'

include_examples :primary_key_parameter, :app_id
include_examples :request_form_body, '#/definitions/SchemeOptions'
include_examples :request_body, '#/definitions/SchemeOptions'

produces 'application/json'
response 201, I18n.t('api.schemes.default.responses.create') do
Expand All @@ -49,7 +49,7 @@
operationId 'updateScheme'

include_examples :primary_key_parameter
include_examples :request_form_body, '#/definitions/SchemeOptions'
include_examples :request_body, '#/definitions/SchemeOptions'

produces 'application/json'
response 200, I18n.t('api.schemes.default.responses.update') do
Expand Down
4 changes: 2 additions & 2 deletions spec/api/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
description I18n.t('api.users.create.description')
operationId 'createUser'

include_examples :request_form_body, '#/definitions/UserOptions'
include_examples :request_body, '#/definitions/UserOptions'

produces 'application/json'
response 201, I18n.t('api.users.default.responses.create') do
Expand All @@ -87,7 +87,7 @@
operationId 'updateUser'

include_examples :primary_key_parameter
include_examples :request_form_body, '#/definitions/UserOptions'
include_examples :request_body, '#/definitions/UserOptions'

produces 'application/json'
response 200, I18n.t('api.users.default.responses.update') do
Expand Down
6 changes: 6 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
# triggering implicit auto-inclusion in groups with matching metadata.
config.shared_context_metadata_behavior = :apply_to_host_groups

config.before :all do
locale = ENV['DEFAULT_LOCALE']
puts "========= #{locale} ========="
I18n.locale = locale.to_sym if locale.present?
end

# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
=begin
Expand Down
16 changes: 16 additions & 0 deletions spec/support/swagger/shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@
parameter name: :build_version, in: query, type: type, required: required, **options
end

# workaround to request both form data and json of body
# ref: https://github.com/rswag/rswag/issues/528#issuecomment-1929012414
shared_examples :request_body do |ref, **options|
metadata[:operation][:requestBody] = {
required: true,
content: {
'application/json': {
schema: { '$ref': ref }
},
'multipart/form-data': {
schema: { '$ref': ref }
}
}
}
end

shared_examples :request_form_body do |ref, **options|
consumes 'multipart/form-data'
parameter name: :body, in: :body, schema: { '$ref': ref }, **options
Expand Down
Loading

0 comments on commit f2ddae5

Please sign in to comment.