add: repository webhooks
This commit is contained in:
parent
8905f60265
commit
ebc4305ca8
|
@ -0,0 +1,24 @@
|
|||
class Projects::WebhooksController < Projects::BaseController
|
||||
|
||||
def index
|
||||
@webhooks = @project.webhooks
|
||||
@webhooks = kaminari_paginate(@webhooks)
|
||||
end
|
||||
|
||||
def create
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
end
|
||||
|
||||
def destroy
|
||||
end
|
||||
|
||||
private
|
||||
def find_webhook
|
||||
@webhook = Gitea::Webhook.find_by_id(params[:id])
|
||||
end
|
||||
end
|
|
@ -867,3 +867,88 @@ await octokit.request('GET /api/jasder/jasder_test/sub_entries.json')
|
|||
<aside class="success">
|
||||
Success Data.
|
||||
</aside>
|
||||
|
||||
## 获取仓库webhooks列表
|
||||
获取仓库webhooks列表
|
||||
|
||||
> 示例:
|
||||
|
||||
```shell
|
||||
curl -X GET \
|
||||
http://localhost:3000/api/yystopf/ceshi/webhooks.json
|
||||
```
|
||||
|
||||
```javascript
|
||||
await octokit.request('GET /api/yystopf/ceshi/webhooks.json')
|
||||
```
|
||||
|
||||
### HTTP 请求
|
||||
`GET /api/:owner/:repo/webhooks.json`
|
||||
|
||||
### 请求参数:
|
||||
参数 | 必选 | 默认 | 类型 | 字段说明
|
||||
--------- | ------- | ------- | -------- | ----------
|
||||
|owner |是| |string |用户登录名 |
|
||||
|repo |是| |string |项目标识identifier |
|
||||
|
||||
|
||||
### 返回字段说明:
|
||||
参数 | 类型 | 字段说明
|
||||
--------- | ----------- | -----------
|
||||
|id |int |id |
|
||||
|url |string|地址|
|
||||
|http_method |string|请求方式|
|
||||
|is_active |bool |是否激活|
|
||||
|type |string|类型|
|
||||
|last_status |string|最后一次推送的状态|
|
||||
|create_time |string|创建时间|
|
||||
|
||||
|
||||
> 返回的JSON示例:
|
||||
|
||||
```json
|
||||
{
|
||||
"total_count": 4,
|
||||
"webhooks": [
|
||||
{
|
||||
"id": 2,
|
||||
"url": "https://oapi.dingtalk.com/robot/send?access_token=7e1e19d0eddb6a5e33c5c2c4e66f4c88f9437184b9ed2c2653194c6374c7d513",
|
||||
"http_method": "",
|
||||
"is_active": true,
|
||||
"type": "dingtalk",
|
||||
"last_status": "succeed",
|
||||
"create_time": "2021-07-12 10:50:07"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"url": "http://localhost:3000",
|
||||
"http_method": "GET",
|
||||
"is_active": true,
|
||||
"type": "gitea",
|
||||
"last_status": "succeed",
|
||||
"create_time": "2021-07-26 10:03:45"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"url": "http://localhost:10081",
|
||||
"http_method": "POST",
|
||||
"is_active": true,
|
||||
"type": "gitea",
|
||||
"last_status": "waiting",
|
||||
"create_time": "2021-07-26 16:56:53"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"url": "http://localhost:3001",
|
||||
"http_method": "POST",
|
||||
"is_active": true,
|
||||
"type": "gitea",
|
||||
"last_status": "fail",
|
||||
"create_time": "2021-07-26 16:58:23"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
<aside class="success">
|
||||
Success Data.
|
||||
</aside>
|
||||
|
|
|
@ -4,6 +4,6 @@ class Gitea::PublicKey < Gitea::Base
|
|||
|
||||
self.table_name = "public_key"
|
||||
|
||||
belongs_to :user, class_name: '::User', foreign_key: :gitea_uid, primary_key: :owner_id, optional: true
|
||||
belongs_to :user, class_name: '::User', primary_key: :gitea_uid, foreign_key: :owner_id, optional: true
|
||||
|
||||
end
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
class Gitea::Webhook < Gitea::Base
|
||||
self.inheritance_column = nil
|
||||
|
||||
self.table_name = 'webhook'
|
||||
|
||||
belongs_to :project, class_name: "::Project", primary_key: :gpid, foreign_key: :repo_id, optional: true
|
||||
|
||||
enum hook_task_type: {gogs: 1, slack: 2, gitea: 3, discord: 4, dingtalk: 5, telegram: 6, msteams: 7, feishu: 8, matrix: 9}
|
||||
enum last_status: {waiting: 0, succeed: 1, fail: 2}
|
||||
end
|
|
@ -125,6 +125,7 @@ class Project < ApplicationRecord
|
|||
has_one :applied_transfer_project,-> { order created_at: :desc }, dependent: :destroy
|
||||
has_many :pinned_projects, dependent: :destroy
|
||||
has_many :has_pinned_users, through: :pinned_projects, source: :user
|
||||
has_many :webhooks, class_name: "Gitea::Webhook", primary_key: :gpid, foreign_key: :repo_id
|
||||
|
||||
after_save :check_project_members, :reset_cache_data
|
||||
before_save :set_invite_code
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
json.(webhook, :id, :url, :http_method, :is_active)
|
||||
json.type webhook.hook_task_type
|
||||
json.last_status webhook.last_status
|
||||
json.create_time Time.at(webhook.created_unix).strftime("%Y-%m-%d %H:%M:%S")
|
|
@ -0,0 +1,4 @@
|
|||
json.total_count @webhooks.total_count
|
||||
json.webhooks @webhooks.each do |webhook|
|
||||
json.partial! 'detail', webhook: webhook
|
||||
end
|
|
@ -348,6 +348,7 @@ Rails.application.routes.draw do
|
|||
|
||||
get '/auth/qq/callback', to: 'oauth/qq#create'
|
||||
get '/auth/wechat/callback', to: 'oauth/wechat#create'
|
||||
get '/auth/educoder/callback', to: 'oauth/educoder#create'
|
||||
resource :bind_user, only: [:create]
|
||||
|
||||
resources :hot_keywords, only: [:index]
|
||||
|
@ -571,6 +572,7 @@ Rails.application.routes.draw do
|
|||
post :cancel
|
||||
end
|
||||
end
|
||||
resources :webhooks, except: [:show, :new]
|
||||
scope do
|
||||
get(
|
||||
'/blob/*id/diff',
|
||||
|
|
|
@ -487,6 +487,9 @@
|
|||
<li>
|
||||
<a href="#fcc64a694b" class="toc-h2 toc-link" data-title="获取仓库代码子目录或者文件">获取仓库代码子目录或者文件</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#webhooks" class="toc-h2 toc-link" data-title="获取仓库webhooks列表">获取仓库webhooks列表</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
|
@ -6752,6 +6755,135 @@ http://localhost:3000//api/jasder/jasder_test/sub_entries.json
|
|||
<aside class="success">
|
||||
Success Data.
|
||||
</aside>
|
||||
<h2 id='webhooks'>获取仓库webhooks列表</h2>
|
||||
<p>获取仓库webhooks列表</p>
|
||||
|
||||
<blockquote>
|
||||
<p>示例:</p>
|
||||
</blockquote>
|
||||
<div class="highlight"><pre class="highlight shell tab-shell"><code>curl <span class="nt">-X</span> GET <span class="se">\</span>
|
||||
http://localhost:3000/api/yystopf/ceshi/webhooks.json
|
||||
</code></pre></div><div class="highlight"><pre class="highlight javascript tab-javascript"><code><span class="k">await</span> <span class="nx">octokit</span><span class="p">.</span><span class="nx">request</span><span class="p">(</span><span class="dl">'</span><span class="s1">GET /api/yystopf/ceshi/webhooks.json</span><span class="dl">'</span><span class="p">)</span>
|
||||
</code></pre></div><h3 id='http-14'>HTTP 请求</h3>
|
||||
<p><code>GET /api/:owner/:repo/webhooks.json</code></p>
|
||||
<h3 id='2eb6f47757-14'>请求参数:</h3>
|
||||
<table><thead>
|
||||
<tr>
|
||||
<th>参数</th>
|
||||
<th>必选</th>
|
||||
<th>默认</th>
|
||||
<th>类型</th>
|
||||
<th>字段说明</th>
|
||||
</tr>
|
||||
</thead><tbody>
|
||||
<tr>
|
||||
<td>owner</td>
|
||||
<td>是</td>
|
||||
<td></td>
|
||||
<td>string</td>
|
||||
<td>用户登录名</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>repo</td>
|
||||
<td>是</td>
|
||||
<td></td>
|
||||
<td>string</td>
|
||||
<td>项目标识identifier</td>
|
||||
</tr>
|
||||
</tbody></table>
|
||||
<h3 id='7447e4874e-14'>返回字段说明:</h3>
|
||||
<table><thead>
|
||||
<tr>
|
||||
<th>参数</th>
|
||||
<th>类型</th>
|
||||
<th>字段说明</th>
|
||||
</tr>
|
||||
</thead><tbody>
|
||||
<tr>
|
||||
<td>id</td>
|
||||
<td>int</td>
|
||||
<td>id</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>url</td>
|
||||
<td>string</td>
|
||||
<td>地址</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>http_method</td>
|
||||
<td>string</td>
|
||||
<td>请求方式</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>is_active</td>
|
||||
<td>bool</td>
|
||||
<td>是否激活</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>type</td>
|
||||
<td>string</td>
|
||||
<td>类型</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>last_status</td>
|
||||
<td>string</td>
|
||||
<td>最后一次推送的状态</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>create_time</td>
|
||||
<td>string</td>
|
||||
<td>创建时间</td>
|
||||
</tr>
|
||||
</tbody></table>
|
||||
|
||||
<blockquote>
|
||||
<p>返回的JSON示例:</p>
|
||||
</blockquote>
|
||||
<div class="highlight"><pre class="highlight json tab-json"><code><span class="p">{</span><span class="w">
|
||||
</span><span class="nl">"total_count"</span><span class="p">:</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w">
|
||||
</span><span class="nl">"webhooks"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
|
||||
</span><span class="p">{</span><span class="w">
|
||||
</span><span class="nl">"id"</span><span class="p">:</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w">
|
||||
</span><span class="nl">"url"</span><span class="p">:</span><span class="w"> </span><span class="s2">"https://oapi.dingtalk.com/robot/send?access_token=7e1e19d0eddb6a5e33c5c2c4e66f4c88f9437184b9ed2c2653194c6374c7d513"</span><span class="p">,</span><span class="w">
|
||||
</span><span class="nl">"http_method"</span><span class="p">:</span><span class="w"> </span><span class="s2">""</span><span class="p">,</span><span class="w">
|
||||
</span><span class="nl">"is_active"</span><span class="p">:</span><span class="w"> </span><span class="kc">true</span><span class="p">,</span><span class="w">
|
||||
</span><span class="nl">"type"</span><span class="p">:</span><span class="w"> </span><span class="s2">"dingtalk"</span><span class="p">,</span><span class="w">
|
||||
</span><span class="nl">"last_status"</span><span class="p">:</span><span class="w"> </span><span class="s2">"succeed"</span><span class="p">,</span><span class="w">
|
||||
</span><span class="nl">"create_time"</span><span class="p">:</span><span class="w"> </span><span class="s2">"2021-07-12 10:50:07"</span><span class="w">
|
||||
</span><span class="p">},</span><span class="w">
|
||||
</span><span class="p">{</span><span class="w">
|
||||
</span><span class="nl">"id"</span><span class="p">:</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w">
|
||||
</span><span class="nl">"url"</span><span class="p">:</span><span class="w"> </span><span class="s2">"http://localhost:3000"</span><span class="p">,</span><span class="w">
|
||||
</span><span class="nl">"http_method"</span><span class="p">:</span><span class="w"> </span><span class="s2">"GET"</span><span class="p">,</span><span class="w">
|
||||
</span><span class="nl">"is_active"</span><span class="p">:</span><span class="w"> </span><span class="kc">true</span><span class="p">,</span><span class="w">
|
||||
</span><span class="nl">"type"</span><span class="p">:</span><span class="w"> </span><span class="s2">"gitea"</span><span class="p">,</span><span class="w">
|
||||
</span><span class="nl">"last_status"</span><span class="p">:</span><span class="w"> </span><span class="s2">"succeed"</span><span class="p">,</span><span class="w">
|
||||
</span><span class="nl">"create_time"</span><span class="p">:</span><span class="w"> </span><span class="s2">"2021-07-26 10:03:45"</span><span class="w">
|
||||
</span><span class="p">},</span><span class="w">
|
||||
</span><span class="p">{</span><span class="w">
|
||||
</span><span class="nl">"id"</span><span class="p">:</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w">
|
||||
</span><span class="nl">"url"</span><span class="p">:</span><span class="w"> </span><span class="s2">"http://localhost:10081"</span><span class="p">,</span><span class="w">
|
||||
</span><span class="nl">"http_method"</span><span class="p">:</span><span class="w"> </span><span class="s2">"POST"</span><span class="p">,</span><span class="w">
|
||||
</span><span class="nl">"is_active"</span><span class="p">:</span><span class="w"> </span><span class="kc">true</span><span class="p">,</span><span class="w">
|
||||
</span><span class="nl">"type"</span><span class="p">:</span><span class="w"> </span><span class="s2">"gitea"</span><span class="p">,</span><span class="w">
|
||||
</span><span class="nl">"last_status"</span><span class="p">:</span><span class="w"> </span><span class="s2">"waiting"</span><span class="p">,</span><span class="w">
|
||||
</span><span class="nl">"create_time"</span><span class="p">:</span><span class="w"> </span><span class="s2">"2021-07-26 16:56:53"</span><span class="w">
|
||||
</span><span class="p">},</span><span class="w">
|
||||
</span><span class="p">{</span><span class="w">
|
||||
</span><span class="nl">"id"</span><span class="p">:</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w">
|
||||
</span><span class="nl">"url"</span><span class="p">:</span><span class="w"> </span><span class="s2">"http://localhost:3001"</span><span class="p">,</span><span class="w">
|
||||
</span><span class="nl">"http_method"</span><span class="p">:</span><span class="w"> </span><span class="s2">"POST"</span><span class="p">,</span><span class="w">
|
||||
</span><span class="nl">"is_active"</span><span class="p">:</span><span class="w"> </span><span class="kc">true</span><span class="p">,</span><span class="w">
|
||||
</span><span class="nl">"type"</span><span class="p">:</span><span class="w"> </span><span class="s2">"gitea"</span><span class="p">,</span><span class="w">
|
||||
</span><span class="nl">"last_status"</span><span class="p">:</span><span class="w"> </span><span class="s2">"fail"</span><span class="p">,</span><span class="w">
|
||||
</span><span class="nl">"create_time"</span><span class="p">:</span><span class="w"> </span><span class="s2">"2021-07-26 16:58:23"</span><span class="w">
|
||||
</span><span class="p">}</span><span class="w">
|
||||
</span><span class="p">]</span><span class="w">
|
||||
</span><span class="p">}</span><span class="w">
|
||||
</span></code></pre></div>
|
||||
<aside class="success">
|
||||
Success Data.
|
||||
</aside>
|
||||
<h1 id='pulls'>Pulls</h1><h1 id='issues'>Issues</h1><h1 id='organizations'>Organizations</h1><h1 id='teams'>Teams</h1><h1 id='errors'>Errors</h1>
|
||||
<aside class="notice">
|
||||
This error section is stored in a separate file in <code>includes/_errors.md</code>. Slate allows you to optionally separate out your docs into many files...just save them to the <code>includes</code> folder and add them to the top of your <code>index.md</code>'s frontmatter. Files are included in the order listed.
|
||||
|
|
Loading…
Reference in New Issue