plugin-git-manager 1.2.21 → 1.2.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/{434.1d19d4d6acc114f1.js → 434.b2eeaaef33aae6e0.js} +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client-v2/{434.f8836ea116648de1.js → 434.7a27051db18526c0.js} +1 -1
- package/dist/client-v2/index.js +1 -1
- package/dist/server/actions/role-permissions.js +124 -54
- package/dist/server/migrations/20260730000000-migrate-legacy-repository-permissions.js +78 -0
- package/dist/server/plugin.js +2 -0
- package/dist/server/repository-access.js +92 -0
- package/package.json +1 -1
- package/src/client/components/RepositoryConfig.tsx +4 -1
- package/src/server/__tests__/repository-access.test.ts +58 -0
- package/src/server/__tests__/role-permissions.test.ts +26 -0
- package/src/server/actions/role-permissions.ts +129 -59
- package/src/server/migrations/20260730000000-migrate-legacy-repository-permissions.ts +66 -0
- package/src/server/plugin.ts +3 -0
- package/src/server/repository-access.ts +64 -0
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
"use strict";(self.webpackChunkplugin_git_manager=self.webpackChunkplugin_git_manager||[]).push([["434"],{33:function(e,t,r){r.d(t,{RepositoryConfigSettings:function(){return y}});var n=r(155),a=r.n(n),l=r(59),o=r(375),u=r(866),i=r(602),c=r(578);function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function d(e,t,r,n,a,l,o){try{var u=e[l](o),i=u.value}catch(e){r(e);return}u.done?t(i):Promise.resolve(i).then(n,a)}function f(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var l=e.apply(t,r);function o(e){d(l,n,a,o,u,"next",e)}function u(e){d(l,n,a,o,u,"throw",e)}o(void 0)})}}function p(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,a=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=a){var l=[],o=!0,u=!1;try{for(a=a.call(e);!(o=(r=a.next()).done)&&(l.push(r.value),!t||l.length!==t);o=!0);}catch(e){u=!0,n=e}finally{try{o||null==a.return||a.return()}finally{if(u)throw n}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return s(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return s(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function m(e,t){var r,n,a,l={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),u=Object.defineProperty;return u(o,"next",{value:i(0)}),u(o,"throw",{value:i(1)}),u(o,"return",{value:i(2)}),"function"==typeof Symbol&&u(o,Symbol.iterator,{value:function(){return this}}),o;function i(u){return function(i){var c=[u,i];if(r)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(l=0)),l;)try{if(r=1,n&&(a=2&c[0]?n.return:c[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,c[1])).done)return a;switch(n=0,a&&(c=[2&c[0],a.value]),c[0]){case 0:case 1:a=c;break;case 4:return l.label++,{value:c[1],done:!1};case 5:l.label++,n=c[1],c=[0];continue;case 7:c=l.ops.pop(),l.trys.pop();continue;default:if(!(a=(a=l.trys).length>0&&a[a.length-1])&&(6===c[0]||2===c[0])){l=0;continue}if(3===c[0]&&(!a||c[1]>a[0]&&c[1]<a[3])){l.label=c[1];break}if(6===c[0]&&l.label<a[1]){l.label=a[1],a=c;break}if(a&&l.label<a[2]){l.label=a[2],l.ops.push(c);break}a[2]&&l.ops.pop(),l.trys.pop();continue}c=t.call(e,l)}catch(e){c=[6,e],n=0}finally{r=a=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var h=function(){var e=(0,c.k)(),t=(0,u.useApp)().apiClient,r=(0,i.B)(),s=r.repos,d=r.refreshRepos,h=r.selectedRepo,y=r.setSelectedRepo,v=p((0,n.useState)(!1),2),b=v[0],g=v[1],w=p((0,n.useState)(null),2),E=w[0],S=w[1],I=p(l.Form.useForm(),1)[0],R=p((0,n.useState)(null),2),k=R[0],C=R[1],A=p((0,n.useState)([]),2),F=A[0],O=A[1],x=p((0,n.useState)([]),2),P=x[0],j=x[1],B=(0,n.useCallback)(function(){return f(function(){var e;return m(this,function(r){switch(r.label){case 0:return[4,t.request({url:"gitReviewFlows:list",params:{pageSize:100,filter:{enabled:!0,triggerMode:{$in:["onMergeRequestCreated","both"]}}}})];case 1:return O((null==(e=r.sent().data)?void 0:e.data)||[]),[2]}})})()},[t]),q=(0,n.useCallback)(function(){return f(function(){var e;return m(this,function(r){switch(r.label){case 0:return[4,t.request({url:"gitAccounts:list",params:{pageSize:100}})];case 1:return j((null==(e=r.sent().data)?void 0:e.data)||[]),[2]}})})()},[t]);(0,n.useEffect)(function(){B().catch(function(){}),q().catch(function(){})},[B,q]),(0,n.useEffect)(function(){d().catch(function(){})},[d]);var T=function(t){return F.filter(function(e){return e.repositoryId===t||null==e.repositoryId}).map(function(t){return{value:t.id,label:"".concat(t.name).concat(null==t.repositoryId?" (".concat(e("global"),")"):"")}})},z=[{title:e("Repository Name"),dataIndex:"name",key:"name",render:function(e,t){return a().createElement("a",{onClick:function(){return y(t)}},e)}},{title:e("Repository URL"),dataIndex:"repoUrl",key:"repoUrl",ellipsis:!0},{title:e("Git Account"),dataIndex:"gitAccountId",key:"gitAccountId",width:160,render:function(t){if(!t)return a().createElement(l.Tag,null,e("None"));var r=P.find(function(e){return e.id===t});return r?r.name:a().createElement(l.Tag,null,e("None"))}},{title:e("Local Path"),dataIndex:"localPath",key:"localPath",ellipsis:!0},{title:e("Default Branch"),dataIndex:"defaultBranch",key:"defaultBranch",width:120},{title:a().createElement(l.Tooltip,{title:e("Auto-poll new merge requests every 5 minutes")},a().createElement(l.Space,{size:4},a().createElement(o.RobotOutlined,null),e("Auto Review"))),dataIndex:"autoReview",key:"autoReview",width:110,render:function(r,n){return a().createElement(l.Switch,{size:"small",checked:!!r,onChange:function(r){return f(function(){var a,o,u,i;return m(this,function(c){switch(c.label){case 0:return c.trys.push([0,3,,4]),u=T(n.id),[4,t.request({url:"gitRepositories:update",method:"post",params:{filterByTk:n.id},data:{autoReview:r,autoReviewFlowId:r&&!n.autoReviewFlowId?null!=(a=null==(o=u[0])?void 0:o.value)?a:null:n.autoReviewFlowId}})];case 1:return c.sent(),[4,d()];case 2:return c.sent(),[3,4];case 3:return i=c.sent(),l.message.error((null==i?void 0:i.message)||e("Failed to save")),[3,4];case 4:return[2]}})})()}})}},{title:e("Primary Auto Flow"),dataIndex:"autoReviewFlowId",key:"autoReviewFlowId",width:220,render:function(r,n){var o=T(n.id);return a().createElement(l.Select,{allowClear:!0,size:"small",style:{width:"100%"},disabled:!n.autoReview,placeholder:e("Select a flow"),value:r||void 0,options:o,notFoundContent:e("No matching flow available"),onChange:function(r){return f(function(){var a;return m(this,function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),[4,t.request({url:"gitRepositories:update",method:"post",params:{filterByTk:n.id},data:{autoReviewFlowId:r||null}})];case 1:return o.sent(),[4,d()];case 2:return o.sent(),[3,4];case 3:return a=o.sent(),l.message.error((null==a?void 0:a.message)||e("Failed to save")),[3,4];case 4:return[2]}})})()}})}},{title:e("Status"),dataIndex:"status",key:"status",width:120,render:function(t){var r={connected:{color:"green",label:e("Connected")},error:{color:"red",label:e("Error")}}[t]||{color:"default",label:e("Disconnected")};return a().createElement(l.Tag,{color:r.color},r.label)}},{title:"",key:"actions",width:200,render:function(r,n){return a().createElement(l.Space,{size:"small"},"connected"!==n.status&&a().createElement(l.Button,{size:"small",icon:a().createElement(o.LinkOutlined,null),loading:k==="clone-".concat(n.id),onClick:function(){return f(function(){var r,a,o,u,i;return m(this,function(c){switch(c.label){case 0:C("clone-".concat(n.id)),c.label=1;case 1:return c.trys.push([1,4,5,6]),[4,t.request({url:"gitManager:clone",method:"post",params:{repositoryId:n.id}})];case 2:return c.sent(),l.message.success(e("Clone successful")),[4,d()];case 3:return c.sent(),[3,6];case 4:return r=c.sent(),l.message.error((null==r||null==(i=r.response)||null==(u=i.data)||null==(o=u.errors)||null==(a=o[0])?void 0:a.message)||e("Clone failed")),[3,6];case 5:return C(null),[7];case 6:return[2]}})})()}},e("Clone")),a().createElement(l.Button,{size:"small",onClick:function(){S(n),I.setFieldsValue(n),g(!0)}},e("Edit")),a().createElement(l.Popconfirm,{title:e("Delete this repository?"),onConfirm:function(){var r;return r=n.id,f(function(){return m(this,function(n){switch(n.label){case 0:return[4,t.request({url:"gitRepositories:destroy",method:"post",params:{filterByTk:r}})];case 1:return n.sent(),(null==h?void 0:h.id)===r&&y(null),l.message.success(e("Deleted")),[4,d()];case 2:return n.sent(),[2]}})})()}},a().createElement(l.Button,{size:"small",danger:!0,icon:a().createElement(o.DeleteOutlined,null)})))}}];return a().createElement("div",null,a().createElement("div",{style:{marginBottom:16}},a().createElement(l.Button,{type:"primary",icon:a().createElement(o.PlusOutlined,null),onClick:function(){S(null),I.resetFields(),g(!0)}},e("Add Repository"))),a().createElement(l.Table,{dataSource:s,columns:z,rowKey:"id",size:"small",pagination:!1,rowClassName:function(e){return(null==h?void 0:h.id)===e.id?"ant-table-row-selected":""}}),a().createElement(l.Modal,{title:E?e("Edit Repository"):e("Add Repository"),open:b,onOk:function(){return f(function(){var r,n;return m(this,function(a){switch(a.label){case 0:return[4,I.validateFields()];case 1:r=a.sent(),a.label=2;case 2:if(a.trys.push([2,8,,9]),!E)return[3,4];return[4,t.request({url:"gitRepositories:update",method:"post",params:{filterByTk:E.id},data:r})];case 3:return a.sent(),l.message.success(e("Repository updated")),[3,6];case 4:return[4,t.request({url:"gitRepositories:create",method:"post",data:r})];case 5:a.sent(),l.message.success(e("Repository added")),a.label=6;case 6:return g(!1),S(null),I.resetFields(),[4,d()];case 7:return a.sent(),[3,9];case 8:return n=a.sent(),l.message.error((null==n?void 0:n.message)||e("Failed to save")),[3,9];case 9:return[2]}})})()},onCancel:function(){g(!1),S(null)},width:520},a().createElement(l.Form,{form:I,layout:"vertical",initialValues:{defaultBranch:"main"}},a().createElement(l.Form.Item,{name:"name",label:e("Repository Name"),rules:[{required:!0}]},a().createElement(l.Input,{placeholder:"my-project"})),a().createElement(l.Form.Item,{name:"repoUrl",label:e("Repository URL"),rules:[{required:!0}]},a().createElement(l.Input,{placeholder:"https://gitlab.com/user/repo.git"})),a().createElement(l.Form.Item,{name:"gitAccountId",label:e("Git Account"),rules:[{required:!0,message:e("Please select a Git account")}],extra:e("Select the GitLab or GitHub account to use for this repository")},a().createElement(l.Select,{placeholder:e("Select an account"),options:P.map(function(e){return{value:e.id,label:"".concat(e.name," (").concat(e.username,")")}}),notFoundContent:e("No accounts configured. Add one in the Git Accounts tab.")})),a().createElement(l.Form.Item,{name:"localPath",label:e("Local Path"),rules:[{required:!0}]},a().createElement(l.Input,{placeholder:"my-project"})),a().createElement(l.Form.Item,{name:"defaultBranch",label:e("Default Branch")},a().createElement(l.Input,{placeholder:"main"})),a().createElement(l.Form.Item,{name:"autoReviewFlowId",label:e("Primary Auto Review Flow"),extra:e("Only flows with automatic trigger modes are shown")},a().createElement(l.Select,{allowClear:!0,placeholder:e("Select a flow"),options:T(null==E?void 0:E.id),notFoundContent:e("No matching flow available")})))))},y=function(){return a().createElement(i.N,null,a().createElement(h,null))}},602:function(e,t,r){r.d(t,{B:function(){return f},N:function(){return p}});var n=r(155),a=r.n(n),l=r(866);function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function u(e,t,r,n,a,l,o){try{var u=e[l](o),i=u.value}catch(e){r(e);return}u.done?t(i):Promise.resolve(i).then(n,a)}function i(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var l=e.apply(t,r);function o(e){u(l,n,a,o,i,"next",e)}function i(e){u(l,n,a,o,i,"throw",e)}o(void 0)})}}function c(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,a=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=a){var l=[],o=!0,u=!1;try{for(a=a.call(e);!(o=(r=a.next()).done)&&(l.push(r.value),!t||l.length!==t);o=!0);}catch(e){u=!0,n=e}finally{try{o||null==a.return||a.return()}finally{if(u)throw n}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return o(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return o(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e,t){var r,n,a,l={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),u=Object.defineProperty;return u(o,"next",{value:i(0)}),u(o,"throw",{value:i(1)}),u(o,"return",{value:i(2)}),"function"==typeof Symbol&&u(o,Symbol.iterator,{value:function(){return this}}),o;function i(u){return function(i){var c=[u,i];if(r)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(l=0)),l;)try{if(r=1,n&&(a=2&c[0]?n.return:c[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,c[1])).done)return a;switch(n=0,a&&(c=[2&c[0],a.value]),c[0]){case 0:case 1:a=c;break;case 4:return l.label++,{value:c[1],done:!1};case 5:l.label++,n=c[1],c=[0];continue;case 7:c=l.ops.pop(),l.trys.pop();continue;default:if(!(a=(a=l.trys).length>0&&a[a.length-1])&&(6===c[0]||2===c[0])){l=0;continue}if(3===c[0]&&(!a||c[1]>a[0]&&c[1]<a[3])){l.label=c[1];break}if(6===c[0]&&l.label<a[1]){l.label=a[1],a=c;break}if(a&&l.label<a[2]){l.label=a[2],l.ops.push(c);break}a[2]&&l.ops.pop(),l.trys.pop();continue}c=t.call(e,l)}catch(e){c=[6,e],n=0}finally{r=a=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var d=(0,n.createContext)(null);function f(){var e=(0,n.useContext)(d);if(!e)throw Error("useGitManager must be used within GitManagerProvider");return e}var p=function(e){var t=e.children,r=(0,l.useApp)().apiClient,o=c((0,n.useState)([]),2),u=o[0],f=o[1],p=c((0,n.useState)(null),2),m=p[0],h=p[1],y=c((0,n.useState)(!1),2),v=y[0],b=y[1],g=c((0,n.useState)([]),2),w=g[0],E=g[1],S=c((0,n.useState)(""),2),I=S[0],R=S[1],k=(0,n.useRef)(m);k.current=m;var C=(0,n.useCallback)(function(){return i(function(){var e,t,n,a;return s(this,function(l){switch(l.label){case 0:if(!(e=k.current)||"connected"!==e.status)return E([]),R(""),[2];l.label=1;case 1:return l.trys.push([1,3,,4]),[4,r.request({url:"gitManager:branches",params:{repositoryId:e.id}})];case 2:return(a=(null==(n=l.sent().data)||null==(t=n.data)?void 0:t.data)||(null==n?void 0:n.data))&&(E(a.all||[]),R(a.current||"")),[3,4];case 3:return l.sent(),E([]),R(""),[3,4];case 4:return[2]}})})()},[r]),A=(0,n.useCallback)(function(){return i(function(){var e,t,n,a;return s(this,function(l){switch(l.label){case 0:b(!0),l.label=1;case 1:return l.trys.push([1,,3,4]),[4,r.request({url:"gitRepositories:list",params:{pageSize:100}})];case 2:return f(t=(null==(e=l.sent().data)?void 0:e.data)||[]),(n=k.current)&&(a=t.find(function(e){return e.id===n.id}))&&h(a),[3,4];case 3:return b(!1),[7];case 4:return[2]}})})()},[r]);return a().createElement(d.Provider,{value:{repos:u,selectedRepo:m,loading:v,branches:w,currentBranch:I,setSelectedRepo:h,refreshRepos:A,refreshBranches:C}},t)}},578:function(e,t,r){r.d(t,{k:function(){return a}});var n=r(866);function a(){var e=(0,n.useApp)();return function(t,r){return e.i18n.t(t,function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){var n;n=r[t],t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n})}return e}({ns:["plugin-git-manager","client"]},r))}}}}]);
|
|
10
|
+
"use strict";(self.webpackChunkplugin_git_manager=self.webpackChunkplugin_git_manager||[]).push([["434"],{33:function(e,t,r){r.d(t,{RepositoryConfigSettings:function(){return y}});var n=r(155),a=r.n(n),l=r(59),o=r(375),u=r(866),i=r(602),c=r(578);function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function d(e,t,r,n,a,l,o){try{var u=e[l](o),i=u.value}catch(e){r(e);return}u.done?t(i):Promise.resolve(i).then(n,a)}function f(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var l=e.apply(t,r);function o(e){d(l,n,a,o,u,"next",e)}function u(e){d(l,n,a,o,u,"throw",e)}o(void 0)})}}function p(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,a=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=a){var l=[],o=!0,u=!1;try{for(a=a.call(e);!(o=(r=a.next()).done)&&(l.push(r.value),!t||l.length!==t);o=!0);}catch(e){u=!0,n=e}finally{try{o||null==a.return||a.return()}finally{if(u)throw n}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return s(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return s(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function m(e,t){var r,n,a,l={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),u=Object.defineProperty;return u(o,"next",{value:i(0)}),u(o,"throw",{value:i(1)}),u(o,"return",{value:i(2)}),"function"==typeof Symbol&&u(o,Symbol.iterator,{value:function(){return this}}),o;function i(u){return function(i){var c=[u,i];if(r)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(l=0)),l;)try{if(r=1,n&&(a=2&c[0]?n.return:c[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,c[1])).done)return a;switch(n=0,a&&(c=[2&c[0],a.value]),c[0]){case 0:case 1:a=c;break;case 4:return l.label++,{value:c[1],done:!1};case 5:l.label++,n=c[1],c=[0];continue;case 7:c=l.ops.pop(),l.trys.pop();continue;default:if(!(a=(a=l.trys).length>0&&a[a.length-1])&&(6===c[0]||2===c[0])){l=0;continue}if(3===c[0]&&(!a||c[1]>a[0]&&c[1]<a[3])){l.label=c[1];break}if(6===c[0]&&l.label<a[1]){l.label=a[1],a=c;break}if(a&&l.label<a[2]){l.label=a[2],l.ops.push(c);break}a[2]&&l.ops.pop(),l.trys.pop();continue}c=t.call(e,l)}catch(e){c=[6,e],n=0}finally{r=a=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var h=function(){var e=(0,c.k)(),t=(0,u.useApp)().apiClient,r=(0,i.B)(),s=r.repos,d=r.refreshRepos,h=r.selectedRepo,y=r.setSelectedRepo,v=p((0,n.useState)(!1),2),b=v[0],g=v[1],w=p((0,n.useState)(null),2),E=w[0],S=w[1],I=p(l.Form.useForm(),1)[0],R=p((0,n.useState)(null),2),k=R[0],C=R[1],A=p((0,n.useState)([]),2),F=A[0],x=A[1],O=p((0,n.useState)([]),2),P=O[0],j=O[1],B=(0,n.useCallback)(function(){return f(function(){var e;return m(this,function(r){switch(r.label){case 0:return[4,t.request({url:"gitReviewFlows:list",params:{pageSize:100,filter:{enabled:!0,triggerMode:{$in:["onMergeRequestCreated","both"]}}}})];case 1:return x((null==(e=r.sent().data)?void 0:e.data)||[]),[2]}})})()},[t]),q=(0,n.useCallback)(function(){return f(function(){var e;return m(this,function(r){switch(r.label){case 0:return[4,t.request({url:"gitAccounts:list",params:{pageSize:100}})];case 1:return j((null==(e=r.sent().data)?void 0:e.data)||[]),[2]}})})()},[t]);(0,n.useEffect)(function(){B().catch(function(){}),q().catch(function(){})},[B,q]),(0,n.useEffect)(function(){d().catch(function(){})},[d]);var T=function(t){return F.filter(function(e){return e.repositoryId===t||null==e.repositoryId}).map(function(t){return{value:t.id,label:"".concat(t.name).concat(null==t.repositoryId?" (".concat(e("global"),")"):"")}})},z=[{title:e("Repository Name"),dataIndex:"name",key:"name",render:function(e,t){return a().createElement("a",{onClick:function(){return y(t)}},e)}},{title:e("Repository URL"),dataIndex:"repoUrl",key:"repoUrl",ellipsis:!0},{title:e("Git Account"),dataIndex:"gitAccountId",key:"gitAccountId",width:160,render:function(t){if(!t)return a().createElement(l.Tag,null,e("None"));var r=P.find(function(e){return e.id===t});return r?r.name:a().createElement(l.Tag,null,e("None"))}},{title:e("Local Path"),dataIndex:"localPath",key:"localPath",ellipsis:!0},{title:e("Default Branch"),dataIndex:"defaultBranch",key:"defaultBranch",width:120},{title:a().createElement(l.Tooltip,{title:e("Auto-poll new merge requests every 5 minutes")},a().createElement(l.Space,{size:4},a().createElement(o.RobotOutlined,null),e("Auto Review"))),dataIndex:"autoReview",key:"autoReview",width:110,render:function(r,n){return a().createElement(l.Switch,{size:"small",checked:!!r,onChange:function(r){return f(function(){var a,o,u,i;return m(this,function(c){switch(c.label){case 0:return c.trys.push([0,3,,4]),u=T(n.id),[4,t.request({url:"gitRepositories:update",method:"post",params:{filterByTk:n.id},data:{autoReview:r,autoReviewFlowId:r&&!n.autoReviewFlowId?null!=(a=null==(o=u[0])?void 0:o.value)?a:null:n.autoReviewFlowId}})];case 1:return c.sent(),[4,d()];case 2:return c.sent(),[3,4];case 3:return i=c.sent(),l.message.error((null==i?void 0:i.message)||e("Failed to save")),[3,4];case 4:return[2]}})})()}})}},{title:e("Primary Auto Flow"),dataIndex:"autoReviewFlowId",key:"autoReviewFlowId",width:220,render:function(r,n){var o=T(n.id);return a().createElement(l.Select,{allowClear:!0,size:"small",style:{width:"100%"},disabled:!n.autoReview,placeholder:e("Select a flow"),value:r||void 0,options:o,notFoundContent:e("No matching flow available"),onChange:function(r){return f(function(){var a;return m(this,function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),[4,t.request({url:"gitRepositories:update",method:"post",params:{filterByTk:n.id},data:{autoReviewFlowId:r||null}})];case 1:return o.sent(),[4,d()];case 2:return o.sent(),[3,4];case 3:return a=o.sent(),l.message.error((null==a?void 0:a.message)||e("Failed to save")),[3,4];case 4:return[2]}})})()}})}},{title:e("Status"),dataIndex:"status",key:"status",width:120,render:function(t){var r={connected:{color:"green",label:e("Connected")},error:{color:"red",label:e("Error")}}[t]||{color:"default",label:e("Disconnected")};return a().createElement(l.Tag,{color:r.color},r.label)}},{title:"",key:"actions",width:200,render:function(r,n){return a().createElement(l.Space,{size:"small"},"connected"!==n.status&&a().createElement(l.Button,{size:"small",icon:a().createElement(o.LinkOutlined,null),loading:k==="clone-".concat(n.id),onClick:function(){return f(function(){var r,a,o,u,i;return m(this,function(c){switch(c.label){case 0:C("clone-".concat(n.id)),c.label=1;case 1:return c.trys.push([1,4,5,6]),[4,t.request({url:"gitManager:clone",method:"post",params:{repositoryId:n.id}})];case 2:return c.sent(),l.message.success(e("Clone successful")),[4,d()];case 3:return c.sent(),[3,6];case 4:return r=c.sent(),l.message.error((null==r||null==(i=r.response)||null==(u=i.data)||null==(o=u.errors)||null==(a=o[0])?void 0:a.message)||e("Clone failed")),[3,6];case 5:return C(null),[7];case 6:return[2]}})})()}},e("Clone")),a().createElement(l.Button,{size:"small",onClick:function(){S(n),I.setFieldsValue(n),g(!0)}},e("Edit")),a().createElement(l.Popconfirm,{title:e("Delete this repository?"),onConfirm:function(){var r;return r=n.id,f(function(){return m(this,function(n){switch(n.label){case 0:return[4,t.request({url:"gitRepositories:destroy",method:"post",params:{filterByTk:r}})];case 1:return n.sent(),(null==h?void 0:h.id)===r&&y(null),l.message.success(e("Deleted")),[4,d()];case 2:return n.sent(),[2]}})})()}},a().createElement(l.Button,{size:"small",danger:!0,icon:a().createElement(o.DeleteOutlined,null)})))}}];return a().createElement("div",null,a().createElement("div",{style:{marginBottom:16}},a().createElement(l.Button,{type:"primary",icon:a().createElement(o.PlusOutlined,null),onClick:function(){S(null),I.resetFields(),g(!0)}},e("Add Repository"))),a().createElement(l.Table,{dataSource:s,columns:z,rowKey:"id",size:"small",pagination:!1,rowClassName:function(e){return(null==h?void 0:h.id)===e.id?"ant-table-row-selected":""}}),a().createElement(l.Modal,{title:E?e("Edit Repository"):e("Add Repository"),open:b,onOk:function(){return f(function(){var r,n;return m(this,function(a){switch(a.label){case 0:return[4,I.validateFields()];case 1:r=a.sent(),a.label=2;case 2:if(a.trys.push([2,8,,9]),!E)return[3,4];return[4,t.request({url:"gitRepositories:update",method:"post",params:{filterByTk:E.id},data:r})];case 3:return a.sent(),l.message.success(e("Repository updated")),[3,6];case 4:return[4,t.request({url:"gitRepositories:create",method:"post",data:r})];case 5:a.sent(),l.message.success(e("Repository added")),a.label=6;case 6:return g(!1),S(null),I.resetFields(),[4,d()];case 7:return a.sent(),[3,9];case 8:return n=a.sent(),l.message.error((null==n?void 0:n.message)||e("Failed to save")),[3,9];case 9:return[2]}})})()},onCancel:function(){g(!1),S(null)},width:520},a().createElement(l.Form,{form:I,layout:"vertical",initialValues:{defaultBranch:"main",registryExportEnabled:!1}},a().createElement(l.Form.Item,{name:"name",label:e("Repository Name"),rules:[{required:!0}]},a().createElement(l.Input,{placeholder:"my-project"})),a().createElement(l.Form.Item,{name:"repoUrl",label:e("Repository URL"),rules:[{required:!0}]},a().createElement(l.Input,{placeholder:"https://gitlab.com/user/repo.git"})),a().createElement(l.Form.Item,{name:"gitAccountId",label:e("Git Account"),rules:[{required:!0,message:e("Please select a Git account")}],extra:e("Select the GitLab or GitHub account to use for this repository")},a().createElement(l.Select,{placeholder:e("Select an account"),options:P.map(function(e){return{value:e.id,label:"".concat(e.name," (").concat(e.username,")")}}),notFoundContent:e("No accounts configured. Add one in the Git Accounts tab.")})),a().createElement(l.Form.Item,{name:"localPath",label:e("Local Path"),rules:[{required:!0}]},a().createElement(l.Input,{placeholder:"my-project"})),a().createElement(l.Form.Item,{name:"defaultBranch",label:e("Default Branch")},a().createElement(l.Input,{placeholder:"main"})),a().createElement(l.Form.Item,{name:"registryExportEnabled",label:e("Allow Skill Registry export"),valuePropName:"checked"},a().createElement(l.Switch,null)),a().createElement(l.Form.Item,{name:"autoReviewFlowId",label:e("Primary Auto Review Flow"),extra:e("Only flows with automatic trigger modes are shown")},a().createElement(l.Select,{allowClear:!0,placeholder:e("Select a flow"),options:T(null==E?void 0:E.id),notFoundContent:e("No matching flow available")})))))},y=function(){return a().createElement(i.N,null,a().createElement(h,null))}},602:function(e,t,r){r.d(t,{B:function(){return f},N:function(){return p}});var n=r(155),a=r.n(n),l=r(866);function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function u(e,t,r,n,a,l,o){try{var u=e[l](o),i=u.value}catch(e){r(e);return}u.done?t(i):Promise.resolve(i).then(n,a)}function i(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var l=e.apply(t,r);function o(e){u(l,n,a,o,i,"next",e)}function i(e){u(l,n,a,o,i,"throw",e)}o(void 0)})}}function c(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,a=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=a){var l=[],o=!0,u=!1;try{for(a=a.call(e);!(o=(r=a.next()).done)&&(l.push(r.value),!t||l.length!==t);o=!0);}catch(e){u=!0,n=e}finally{try{o||null==a.return||a.return()}finally{if(u)throw n}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return o(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return o(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e,t){var r,n,a,l={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),u=Object.defineProperty;return u(o,"next",{value:i(0)}),u(o,"throw",{value:i(1)}),u(o,"return",{value:i(2)}),"function"==typeof Symbol&&u(o,Symbol.iterator,{value:function(){return this}}),o;function i(u){return function(i){var c=[u,i];if(r)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(l=0)),l;)try{if(r=1,n&&(a=2&c[0]?n.return:c[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,c[1])).done)return a;switch(n=0,a&&(c=[2&c[0],a.value]),c[0]){case 0:case 1:a=c;break;case 4:return l.label++,{value:c[1],done:!1};case 5:l.label++,n=c[1],c=[0];continue;case 7:c=l.ops.pop(),l.trys.pop();continue;default:if(!(a=(a=l.trys).length>0&&a[a.length-1])&&(6===c[0]||2===c[0])){l=0;continue}if(3===c[0]&&(!a||c[1]>a[0]&&c[1]<a[3])){l.label=c[1];break}if(6===c[0]&&l.label<a[1]){l.label=a[1],a=c;break}if(a&&l.label<a[2]){l.label=a[2],l.ops.push(c);break}a[2]&&l.ops.pop(),l.trys.pop();continue}c=t.call(e,l)}catch(e){c=[6,e],n=0}finally{r=a=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var d=(0,n.createContext)(null);function f(){var e=(0,n.useContext)(d);if(!e)throw Error("useGitManager must be used within GitManagerProvider");return e}var p=function(e){var t=e.children,r=(0,l.useApp)().apiClient,o=c((0,n.useState)([]),2),u=o[0],f=o[1],p=c((0,n.useState)(null),2),m=p[0],h=p[1],y=c((0,n.useState)(!1),2),v=y[0],b=y[1],g=c((0,n.useState)([]),2),w=g[0],E=g[1],S=c((0,n.useState)(""),2),I=S[0],R=S[1],k=(0,n.useRef)(m);k.current=m;var C=(0,n.useCallback)(function(){return i(function(){var e,t,n,a;return s(this,function(l){switch(l.label){case 0:if(!(e=k.current)||"connected"!==e.status)return E([]),R(""),[2];l.label=1;case 1:return l.trys.push([1,3,,4]),[4,r.request({url:"gitManager:branches",params:{repositoryId:e.id}})];case 2:return(a=(null==(n=l.sent().data)||null==(t=n.data)?void 0:t.data)||(null==n?void 0:n.data))&&(E(a.all||[]),R(a.current||"")),[3,4];case 3:return l.sent(),E([]),R(""),[3,4];case 4:return[2]}})})()},[r]),A=(0,n.useCallback)(function(){return i(function(){var e,t,n,a;return s(this,function(l){switch(l.label){case 0:b(!0),l.label=1;case 1:return l.trys.push([1,,3,4]),[4,r.request({url:"gitRepositories:list",params:{pageSize:100}})];case 2:return f(t=(null==(e=l.sent().data)?void 0:e.data)||[]),(n=k.current)&&(a=t.find(function(e){return e.id===n.id}))&&h(a),[3,4];case 3:return b(!1),[7];case 4:return[2]}})})()},[r]);return a().createElement(d.Provider,{value:{repos:u,selectedRepo:m,loading:v,branches:w,currentBranch:I,setSelectedRepo:h,refreshRepos:A,refreshBranches:C}},t)}},578:function(e,t,r){r.d(t,{k:function(){return a}});var n=r(866);function a(){var e=(0,n.useApp)();return function(t,r){return e.i18n.t(t,function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){var n;n=r[t],t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n})}return e}({ns:["plugin-git-manager","client"]},r))}}}}]);
|
package/dist/client/index.js
CHANGED
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@nocobase/client-v2"),require("react"),require("antd"),require("@nocobase/client"),require("@nocobase/plugin-acl/client"),require("@ant-design/icons"),require("@nocobase/flow-engine"),require("@nocobase/plugin-ai/client")):"function"==typeof define&&define.amd?define("plugin-git-manager",["@nocobase/client-v2","react","antd","@nocobase/client","@nocobase/plugin-acl/client","@ant-design/icons","@nocobase/flow-engine","@nocobase/plugin-ai/client"],t):"object"==typeof exports?exports["plugin-git-manager"]=t(require("@nocobase/client-v2"),require("react"),require("antd"),require("@nocobase/client"),require("@nocobase/plugin-acl/client"),require("@ant-design/icons"),require("@nocobase/flow-engine"),require("@nocobase/plugin-ai/client")):e["plugin-git-manager"]=t(e["@nocobase/client-v2"],e.react,e.antd,e["@nocobase/client"],e["@nocobase/plugin-acl/client"],e["@ant-design/icons"],e["@nocobase/flow-engine"],e["@nocobase/plugin-ai/client"])}(self,function(e,t,n,r,o,i,a,u){return function(){"use strict";var l,c,s,p={375:function(e){e.exports=i},342:function(e){e.exports=r},866:function(t){t.exports=e},694:function(e){e.exports=a},79:function(e){e.exports=o},75:function(e){e.exports=u},59:function(e){e.exports=n},155:function(e){e.exports=t}},f={};function d(e){var t=f[e];if(void 0!==t)return t.exports;var n=f[e]={exports:{}};return p[e].call(n.exports,n,n.exports,d),n.exports}d.m=p,d.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return d.d(t,{a:t}),t},d.d=function(e,t){for(var n in t)d.o(t,n)&&!d.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},d.f={},d.e=function(e){return Promise.all(Object.keys(d.f).reduce(function(t,n){return d.f[n](e,t),t},[]))},d.u=function(e){return""+e+"."+({156:"c27c2392746e7866",326:"90c276058682b536",356:"a7455fc6b724ee2e",434:"1d19d4d6acc114f1",900:"ee2fa037aff389e2"})[e]+".js"},d.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),d.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},g={},d.l=function(e,t,n,r){if(g[e])return void g[e].push(t);if(void 0!==n)for(var o,i,a=document.getElementsByTagName("script"),u=0;u<a.length;u++){var l=a[u];if(l.getAttribute("src")==e||l.getAttribute("data-rspack")=="plugin-git-manager:"+n){o=l;break}}o||(i=!0,(o=document.createElement("script")).timeout=120,d.nc&&o.setAttribute("nonce",d.nc),o.setAttribute("data-rspack","plugin-git-manager:"+n),o.src=e),g[e]=[t];var c=function(t,n){o.onerror=o.onload=null,clearTimeout(s);var r=g[e];if(delete g[e],o.parentNode&&o.parentNode.removeChild(o),r&&r.forEach(function(e){return e(n)}),t)return t(n)},s=setTimeout(c.bind(null,void 0,{type:"timeout",target:o}),12e4);o.onerror=c.bind(null,o.onerror),o.onload=c.bind(null,o.onload),i&&document.head.appendChild(o)},d.r=function(e){"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},d.g.importScripts&&(m=d.g.location+"");var g,m,b=d.g.document;if(!m&&b&&(b.currentScript&&"SCRIPT"===b.currentScript.tagName.toUpperCase()&&(m=b.currentScript.src),!m)){var y=b.getElementsByTagName("script");if(y.length)for(var h=y.length-1;h>-1&&(!m||!/^http(s?):/.test(m));)m=y[h--].src}if(!m)throw Error("Automatic publicPath is not supported in this browser");d.p=m.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),l={889:0},d.f.j=function(e,t){var n=d.o(l,e)?l[e]:void 0;if(0!==n)if(n)t.push(n[2]);else{var r=new Promise(function(t,r){n=l[e]=[t,r]});t.push(n[2]=r);var o=d.p+d.u(e),i=Error();d.l(o,function(t){if(d.o(l,e)&&(0!==(n=l[e])&&(l[e]=void 0),n)){var r=t&&("load"===t.type?"missing":t.type),o=t&&t.target&&t.target.src;i.message="Loading chunk "+e+" failed.\n("+r+": "+o+")",i.name="ChunkLoadError",i.type=r,i.request=o,n[1](i)}},"chunk-"+e,e)}},c=function(e,t){var n,r,o=t[0],i=t[1],a=t[2],u=0;if(o.some(function(e){return 0!==l[e]})){for(n in i)d.o(i,n)&&(d.m[n]=i[n]);a&&a(d)}for(e&&e(t);u<o.length;u++)r=o[u],d.o(l,r)&&l[r]&&l[r][0](),l[r]=0},(s=self.webpackChunkplugin_git_manager=self.webpackChunkplugin_git_manager||[]).forEach(c.bind(null,0)),s.push=c.bind(null,s.push.bind(s));var v={};return!function(){var e="",t="u">typeof document?document.currentScript:null;if(t&&t.src){var n=t.src.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"");n.indexOf("/static/plugins/plugin-git-manager/dist/client/")>=0&&(e=n.replace(/\/[^\/]+$/,"/"))}if(!e){var r=window.__webpack_public_path__||"";r&&("/"!==r.charAt(r.length-1)&&(r+="/"),e=r+"static/plugins/plugin-git-manager/dist/client/")}if(!e){var o=window.__nocobase_modern_client_prefix__||"v",i="/"+(o=String(o).replace(/^\/+|\/+$/g,"")||"v")+"/";if(!(e=window.__nocobase_public_path__||"")&&window.location&&window.location.pathname){var a=window.location.pathname||"/",u=a.indexOf(i);e=u>=0?a.slice(0,u+1):"/"}e&&(e=e.replace(RegExp("/"+o+"/?$"),"/")),e||(e="/"),"/"!==e.charAt(e.length-1)&&(e+="/"),e+="static/plugins/plugin-git-manager/dist/client/"}d.p=e}(),!function(){d.r(v),d.d(v,{PluginGitManagerClient:function(){return N},default:function(){return G}});var e=d(342),t=d(155),n=d.n(t),r=d(59),o=d(375);function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function a(e,t,n,r,o,i,a){try{var u=e[i](a),l=u.value}catch(e){n(e);return}u.done?t(l):Promise.resolve(l).then(r,o)}function u(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function u(e){a(i,r,o,u,l,"next",e)}function l(e){a(i,r,o,u,l,"throw",e)}u(void 0)})}}function l(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,o=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var i=[],a=!0,u=!1;try{for(o=o.call(e);!(a=(n=o.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){u=!0,r=e}finally{try{a||null==o.return||o.return()}finally{if(u)throw r}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return i(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return i(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),u=Object.defineProperty;return u(a,"next",{value:l(0)}),u(a,"throw",{value:l(1)}),u(a,"return",{value:l(2)}),"function"==typeof Symbol&&u(a,Symbol.iterator,{value:function(){return this}}),a;function l(u){return function(l){var c=[u,l];if(n)throw TypeError("Generator is already executing.");for(;a&&(a=0,c[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,r=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){i=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){i.label=c[1];break}if(6===c[0]&&i.label<o[1]){i.label=o[1],o=c;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(c);break}o[2]&&i.ops.pop(),i.trys.pop();continue}c=t.call(e,i)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var s={name:"git-repository",menu:{icon:n().createElement(o.BranchesOutlined,null),Component:function(){return n().createElement("span",null,"Git Repository")}},tag:{Component:function(e){var t=e.item;return n().createElement(r.Space,{size:4},n().createElement(o.BranchesOutlined,null),n().createElement("span",null,(null==t?void 0:t.title)||"Repo #".concat(null==t?void 0:t.uid)))}},getContent:function(e,t){var n=t.uid;return u(function(){var t,r,o;return c(this,function(i){switch(i.label){case 0:return[4,e.apiClient.request({url:"gitRepositories:get",params:{filterByTk:n}})];case 1:if(!(o=null==(r=i.sent())||null==(t=r.data)?void 0:t.data))return[2,null];return[2,{type:"git-repository",repositoryId:o.id,name:o.name,repoUrl:o.repoUrl,defaultBranch:o.defaultBranch,status:o.status}]}})})()}},p={name:"git-merge-request",menu:{icon:n().createElement(o.MergeOutlined,null),Component:function(){return n().createElement("span",null,"Git Merge Request")}},tag:{Component:function(e){var t=e.item;return n().createElement(r.Space,{size:4},n().createElement(o.MergeOutlined,null),n().createElement("span",null,(null==t?void 0:t.title)||"MR ".concat(null==t?void 0:t.uid)))}},getContent:function(e,t){var n=t.uid;return u(function(){var t,r,o,i,a,u,s,p;return c(this,function(c){switch(c.label){case 0:if(o=(r=l(String(n||"").split(":"),2))[0],i=r[1],a=Number(o),u=Number(i),!a||!u)return[2,null];return[4,e.apiClient.request({url:"gitManager:mergeRequestDetail",params:{repositoryId:a,mrIid:u}})];case 1:return p=null==(s=c.sent())||null==(t=s.data)?void 0:t.data,[2,{type:"git-merge-request",repositoryId:a,mrIid:u,title:null==p?void 0:p.title,sourceBranch:null==p?void 0:p.sourceBranch,targetBranch:null==p?void 0:p.targetBranch,author:null==p?void 0:p.author,changes:null==p?void 0:p.changes,description:null==p?void 0:p.description,webUrl:null==p?void 0:p.webUrl}]}})})()}},f={name:"git-commit",menu:{icon:n().createElement(o.NodeIndexOutlined,null),Component:function(){return n().createElement("span",null,"Git Commit")}},tag:{Component:function(e){var t=e.item;return n().createElement(r.Space,{size:4},n().createElement(o.NodeIndexOutlined,null),n().createElement("span",null,(null==t?void 0:t.title)||"Commit ".concat(null==t?void 0:t.uid)))}},getContent:function(e,t){var n=t.uid;return u(function(){var t,r,o,i,a,u,s;return c(this,function(c){switch(c.label){case 0:if(o=(r=l(String(n||"").split(":"),2))[0],i=r[1],!(a=Number(o))||!i)return[2,null];return[4,e.apiClient.request({url:"gitManager:commitDetail",params:{repositoryId:a,commitHash:i}})];case 1:return s=null==(u=c.sent())||null==(t=u.data)?void 0:t.data,[2,function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}({type:"git-commit",repositoryId:a,commitSha:i},s)]}})})()}},g=d(79),m=d.n(g),b=d(866);function y(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function h(e,t,n,r,o,i,a){try{var u=e[i](a),l=u.value}catch(e){n(e);return}u.done?t(l):Promise.resolve(l).then(r,o)}function w(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function a(e){h(i,r,o,a,u,"next",e)}function u(e){h(i,r,o,a,u,"throw",e)}a(void 0)})}}function O(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function S(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,o=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var i=[],a=!0,u=!1;try{for(o=o.call(e);!(a=(n=o.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){u=!0,r=e}finally{try{a||null==o.return||o.return()}finally{if(u)throw r}}return i}}(e,t)||x(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function j(e){return function(e){if(Array.isArray(e))return y(e)}(e)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||x(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function x(e,t){if(e){if("string"==typeof e)return y(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return y(e,t)}}function E(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),u=Object.defineProperty;return u(a,"next",{value:l(0)}),u(a,"throw",{value:l(1)}),u(a,"return",{value:l(2)}),"function"==typeof Symbol&&u(a,Symbol.iterator,{value:function(){return this}}),a;function l(u){return function(l){var c=[u,l];if(n)throw TypeError("Generator is already executing.");for(;a&&(a=0,c[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,r=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){i=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){i.label=c[1];break}if(6===c[0]&&i.label<o[1]){i.label=o[1],o=c;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(c);break}o[2]&&i.ops.pop(),i.trys.pop();continue}c=t.call(e,i)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var k=function(e){var o=e.activeRole,i=(0,b.useApp)().apiClient,a=S((0,t.useState)(!1),2),u=a[0],l=a[1],c=S((0,t.useState)([]),2),s=c[0],p=c[1],f=S((0,t.useState)({read:[],write:[]}),2),d=f[0],g=f[1];(0,t.useEffect)(function(){(null==o?void 0:o.name)&&m()},[null==o?void 0:o.name]);var m=function(){return w(function(){var e,t,n,a,u,c;return E(this,function(s){switch(s.label){case 0:l(!0),s.label=1;case 1:return s.trys.push([1,3,,4]),[4,Promise.all([i.request({resource:"gitRepositories",action:"list",params:{paginate:!1,sort:["name"]}}),i.request({url:"gitManager:rolePermissions",method:"get",params:{roleName:o.name}})])];case 2:return a=(n=S.apply(void 0,[s.sent(),2]))[0],c=(null==(u=n[1])||null==(e=u.data)?void 0:e.data)||(null==u?void 0:u.data)||{read:[],write:[]},p((null==a||null==(t=a.data)?void 0:t.data)||[]),g({read:c.read||[],write:c.write||[]}),[3,4];case 3:return console.error(s.sent()),r.message.error("Failed to load repository permissions"),[3,4];case 4:return l(!1),[2]}})})()},y=function(e,t,n){return w(function(){var a,u,l,c;return E(this,function(s){switch(s.label){case 0:var p,f;a=d[t]||[],u=n?j(new Set(j(a).concat([e]))):a.filter(function(t){return t!==e}),p=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){O(e,t,n[t])})}return e}({},d),f=null!=(f=O({},t,u))?f:{},Object.getOwnPropertyDescriptors?Object.defineProperties(p,Object.getOwnPropertyDescriptors(f)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t})(Object(f)).forEach(function(e){Object.defineProperty(p,e,Object.getOwnPropertyDescriptor(f,e))}),l=p,c=d,g(l),s.label=1;case 1:return s.trys.push([1,3,,4]),[4,i.request({url:"gitManager:updateRolePermissions",method:"post",data:{roleName:o.name,values:l}})];case 2:return s.sent(),[3,4];case 3:return s.sent(),r.message.error("Failed to update permissions"),g(c),[3,4];case 4:return[2]}})})()},h=[{title:"Repository Name",dataIndex:"name",key:"name",render:function(e){return n().createElement(r.Typography.Text,{strong:!0},e)}},{title:"Repository URL",dataIndex:"repoUrl",key:"repoUrl",ellipsis:!0,render:function(e){return n().createElement(r.Typography.Text,{type:"secondary"},e)}},{title:"Read (List, Browse Files, View History)",key:"read",width:100,render:function(e,t){return n().createElement(r.Checkbox,{checked:(d.read||[]).includes(t.id),onChange:function(e){return y(t.id,"read",e.target.checked)}})}},{title:"Write (Clone, Pull, Push, Review)",key:"write",width:100,render:function(e,t){return n().createElement(r.Checkbox,{checked:(d.write||[]).includes(t.id),onChange:function(e){return y(t.id,"write",e.target.checked)}})}}];return u&&!s.length?n().createElement(r.Spin,{style:{display:"block",margin:"40px auto"}}):n().createElement("div",{style:{padding:16}},n().createElement("div",{style:{marginBottom:16}},n().createElement(r.Typography.Text,{type:"secondary"},"Configure access permissions for each repository for the role"," ",n().createElement(r.Typography.Text,{strong:!0},(null==o?void 0:o.title)||(null==o?void 0:o.name)),".")),n().createElement(r.Table,{dataSource:s,columns:h,rowKey:"id",pagination:!1,size:"small",bordered:!0}))};function P(e,t,n,r,o,i,a){try{var u=e[i](a),l=u.value}catch(e){n(e);return}u.done?t(l):Promise.resolve(l).then(r,o)}function C(e,t,n){return(C=I()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&T(o,n.prototype),o}).apply(null,arguments)}function _(e){return(_=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function T(e,t){return(T=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function q(e){var t="function"==typeof Map?new Map:void 0;return(q=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return C(e,arguments,_(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),T(n,e)})(e)}function I(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(I=function(){return!!e})()}var M=n().lazy(function(){return Promise.all([d.e("326"),d.e("900")]).then(d.bind(d,591)).then(function(e){return{default:e.GitManagerSettings}})}),A=n().lazy(function(){return d.e("434").then(d.bind(d,33)).then(function(e){return{default:e.RepositoryConfigSettings}})}),R=n().lazy(function(){return d.e("156").then(d.bind(d,367)).then(function(e){return{default:e.GitAccountsSettings}})}),B=n().lazy(function(){return d.e("356").then(d.bind(d,935))}),N=function(e){var t;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function r(){var e,t;if(!(this instanceof r))throw TypeError("Cannot call a class as a function");return e=r,t=arguments,e=_(e),function(e,t){var n;if(t&&("object"==((n=t)&&"u">typeof Symbol&&n.constructor===Symbol?"symbol":typeof n)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,I()?Reflect.construct(e,t||[],_(this).constructor):e.apply(this,t))}return r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),e&&T(r,e),t=[{key:"load",value:function(){var e;return(e=function(){var e,t;return function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),u=Object.defineProperty;return u(a,"next",{value:l(0)}),u(a,"throw",{value:l(1)}),u(a,"return",{value:l(2)}),"function"==typeof Symbol&&u(a,Symbol.iterator,{value:function(){return this}}),a;function l(u){return function(l){var c=[u,l];if(n)throw TypeError("Generator is already executing.");for(;a&&(a=0,c[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,r=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){i=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){i.label=c[1];break}if(6===c[0]&&i.label<o[1]){i.label=o[1],o=c;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(c);break}o[2]&&i.ops.pop(),i.trys.pop();continue}c=t.call(e,i)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}(this,function(r){return this.app.pluginSettingsManager.add("git-manager",{title:this.t("Git Manager"),icon:"BranchesOutlined"}),this.app.pluginSettingsManager.add("git-manager.repositories",{title:this.t("Repositories"),Component:A,aclSnippet:"pm.plugin-git-manager.repositories"}),this.app.pluginSettingsManager.add("git-manager.accounts",{title:this.t("Git Accounts"),Component:R,aclSnippet:"pm.plugin-git-manager.repositories"}),this.app.pluginSettingsManager.add("git-manager.subtree-splits",{title:this.t("Subtree Splits"),Component:B,aclSnippet:"pm.plugin-git-manager.write"}),this.app.pluginSettingsManager.add("git-manager.manage",{title:this.t("Manage"),Component:M,aclSnippet:"pm.plugin-git-manager.manage"}),(null==(e=this.app.aiManager)?void 0:e.registerWorkContext)&&(e.registerWorkContext("git-repository",s),e.registerWorkContext("git-merge-request",p),e.registerWorkContext("git-commit",f)),(t=this.app.pm.get(m()))&&t.settingsUI.addPermissionsTab(function(e){e.t;var t=e.TabLayout,r=e.activeRole;return{key:"git-manager",label:"Git Manager",sort:25,children:n().createElement(t,null,n().createElement(k,{activeRole:r}))}}),[2]})},function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function a(e){P(i,r,o,a,u,"next",e)}function u(e){P(i,r,o,a,u,"throw",e)}a(void 0)})}).call(this)}}],function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(r.prototype,t),r}(q(e.Plugin)),G=N}(),v}()});
|
|
10
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@nocobase/client-v2"),require("react"),require("antd"),require("@nocobase/client"),require("@nocobase/plugin-acl/client"),require("@ant-design/icons"),require("@nocobase/flow-engine"),require("@nocobase/plugin-ai/client")):"function"==typeof define&&define.amd?define("plugin-git-manager",["@nocobase/client-v2","react","antd","@nocobase/client","@nocobase/plugin-acl/client","@ant-design/icons","@nocobase/flow-engine","@nocobase/plugin-ai/client"],t):"object"==typeof exports?exports["plugin-git-manager"]=t(require("@nocobase/client-v2"),require("react"),require("antd"),require("@nocobase/client"),require("@nocobase/plugin-acl/client"),require("@ant-design/icons"),require("@nocobase/flow-engine"),require("@nocobase/plugin-ai/client")):e["plugin-git-manager"]=t(e["@nocobase/client-v2"],e.react,e.antd,e["@nocobase/client"],e["@nocobase/plugin-acl/client"],e["@ant-design/icons"],e["@nocobase/flow-engine"],e["@nocobase/plugin-ai/client"])}(self,function(e,t,n,r,o,i,a,u){return function(){"use strict";var l,c,s,p={375:function(e){e.exports=i},342:function(e){e.exports=r},866:function(t){t.exports=e},694:function(e){e.exports=a},79:function(e){e.exports=o},75:function(e){e.exports=u},59:function(e){e.exports=n},155:function(e){e.exports=t}},f={};function d(e){var t=f[e];if(void 0!==t)return t.exports;var n=f[e]={exports:{}};return p[e].call(n.exports,n,n.exports,d),n.exports}d.m=p,d.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return d.d(t,{a:t}),t},d.d=function(e,t){for(var n in t)d.o(t,n)&&!d.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},d.f={},d.e=function(e){return Promise.all(Object.keys(d.f).reduce(function(t,n){return d.f[n](e,t),t},[]))},d.u=function(e){return""+e+"."+({156:"c27c2392746e7866",326:"90c276058682b536",356:"a7455fc6b724ee2e",434:"b2eeaaef33aae6e0",900:"ee2fa037aff389e2"})[e]+".js"},d.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),d.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},g={},d.l=function(e,t,n,r){if(g[e])return void g[e].push(t);if(void 0!==n)for(var o,i,a=document.getElementsByTagName("script"),u=0;u<a.length;u++){var l=a[u];if(l.getAttribute("src")==e||l.getAttribute("data-rspack")=="plugin-git-manager:"+n){o=l;break}}o||(i=!0,(o=document.createElement("script")).timeout=120,d.nc&&o.setAttribute("nonce",d.nc),o.setAttribute("data-rspack","plugin-git-manager:"+n),o.src=e),g[e]=[t];var c=function(t,n){o.onerror=o.onload=null,clearTimeout(s);var r=g[e];if(delete g[e],o.parentNode&&o.parentNode.removeChild(o),r&&r.forEach(function(e){return e(n)}),t)return t(n)},s=setTimeout(c.bind(null,void 0,{type:"timeout",target:o}),12e4);o.onerror=c.bind(null,o.onerror),o.onload=c.bind(null,o.onload),i&&document.head.appendChild(o)},d.r=function(e){"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},d.g.importScripts&&(m=d.g.location+"");var g,m,b=d.g.document;if(!m&&b&&(b.currentScript&&"SCRIPT"===b.currentScript.tagName.toUpperCase()&&(m=b.currentScript.src),!m)){var y=b.getElementsByTagName("script");if(y.length)for(var h=y.length-1;h>-1&&(!m||!/^http(s?):/.test(m));)m=y[h--].src}if(!m)throw Error("Automatic publicPath is not supported in this browser");d.p=m.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),l={889:0},d.f.j=function(e,t){var n=d.o(l,e)?l[e]:void 0;if(0!==n)if(n)t.push(n[2]);else{var r=new Promise(function(t,r){n=l[e]=[t,r]});t.push(n[2]=r);var o=d.p+d.u(e),i=Error();d.l(o,function(t){if(d.o(l,e)&&(0!==(n=l[e])&&(l[e]=void 0),n)){var r=t&&("load"===t.type?"missing":t.type),o=t&&t.target&&t.target.src;i.message="Loading chunk "+e+" failed.\n("+r+": "+o+")",i.name="ChunkLoadError",i.type=r,i.request=o,n[1](i)}},"chunk-"+e,e)}},c=function(e,t){var n,r,o=t[0],i=t[1],a=t[2],u=0;if(o.some(function(e){return 0!==l[e]})){for(n in i)d.o(i,n)&&(d.m[n]=i[n]);a&&a(d)}for(e&&e(t);u<o.length;u++)r=o[u],d.o(l,r)&&l[r]&&l[r][0](),l[r]=0},(s=self.webpackChunkplugin_git_manager=self.webpackChunkplugin_git_manager||[]).forEach(c.bind(null,0)),s.push=c.bind(null,s.push.bind(s));var v={};return!function(){var e="",t="u">typeof document?document.currentScript:null;if(t&&t.src){var n=t.src.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"");n.indexOf("/static/plugins/plugin-git-manager/dist/client/")>=0&&(e=n.replace(/\/[^\/]+$/,"/"))}if(!e){var r=window.__webpack_public_path__||"";r&&("/"!==r.charAt(r.length-1)&&(r+="/"),e=r+"static/plugins/plugin-git-manager/dist/client/")}if(!e){var o=window.__nocobase_modern_client_prefix__||"v",i="/"+(o=String(o).replace(/^\/+|\/+$/g,"")||"v")+"/";if(!(e=window.__nocobase_public_path__||"")&&window.location&&window.location.pathname){var a=window.location.pathname||"/",u=a.indexOf(i);e=u>=0?a.slice(0,u+1):"/"}e&&(e=e.replace(RegExp("/"+o+"/?$"),"/")),e||(e="/"),"/"!==e.charAt(e.length-1)&&(e+="/"),e+="static/plugins/plugin-git-manager/dist/client/"}d.p=e}(),!function(){d.r(v),d.d(v,{PluginGitManagerClient:function(){return N},default:function(){return G}});var e=d(342),t=d(155),n=d.n(t),r=d(59),o=d(375);function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function a(e,t,n,r,o,i,a){try{var u=e[i](a),l=u.value}catch(e){n(e);return}u.done?t(l):Promise.resolve(l).then(r,o)}function u(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function u(e){a(i,r,o,u,l,"next",e)}function l(e){a(i,r,o,u,l,"throw",e)}u(void 0)})}}function l(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,o=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var i=[],a=!0,u=!1;try{for(o=o.call(e);!(a=(n=o.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){u=!0,r=e}finally{try{a||null==o.return||o.return()}finally{if(u)throw r}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return i(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return i(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),u=Object.defineProperty;return u(a,"next",{value:l(0)}),u(a,"throw",{value:l(1)}),u(a,"return",{value:l(2)}),"function"==typeof Symbol&&u(a,Symbol.iterator,{value:function(){return this}}),a;function l(u){return function(l){var c=[u,l];if(n)throw TypeError("Generator is already executing.");for(;a&&(a=0,c[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,r=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){i=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){i.label=c[1];break}if(6===c[0]&&i.label<o[1]){i.label=o[1],o=c;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(c);break}o[2]&&i.ops.pop(),i.trys.pop();continue}c=t.call(e,i)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var s={name:"git-repository",menu:{icon:n().createElement(o.BranchesOutlined,null),Component:function(){return n().createElement("span",null,"Git Repository")}},tag:{Component:function(e){var t=e.item;return n().createElement(r.Space,{size:4},n().createElement(o.BranchesOutlined,null),n().createElement("span",null,(null==t?void 0:t.title)||"Repo #".concat(null==t?void 0:t.uid)))}},getContent:function(e,t){var n=t.uid;return u(function(){var t,r,o;return c(this,function(i){switch(i.label){case 0:return[4,e.apiClient.request({url:"gitRepositories:get",params:{filterByTk:n}})];case 1:if(!(o=null==(r=i.sent())||null==(t=r.data)?void 0:t.data))return[2,null];return[2,{type:"git-repository",repositoryId:o.id,name:o.name,repoUrl:o.repoUrl,defaultBranch:o.defaultBranch,status:o.status}]}})})()}},p={name:"git-merge-request",menu:{icon:n().createElement(o.MergeOutlined,null),Component:function(){return n().createElement("span",null,"Git Merge Request")}},tag:{Component:function(e){var t=e.item;return n().createElement(r.Space,{size:4},n().createElement(o.MergeOutlined,null),n().createElement("span",null,(null==t?void 0:t.title)||"MR ".concat(null==t?void 0:t.uid)))}},getContent:function(e,t){var n=t.uid;return u(function(){var t,r,o,i,a,u,s,p;return c(this,function(c){switch(c.label){case 0:if(o=(r=l(String(n||"").split(":"),2))[0],i=r[1],a=Number(o),u=Number(i),!a||!u)return[2,null];return[4,e.apiClient.request({url:"gitManager:mergeRequestDetail",params:{repositoryId:a,mrIid:u}})];case 1:return p=null==(s=c.sent())||null==(t=s.data)?void 0:t.data,[2,{type:"git-merge-request",repositoryId:a,mrIid:u,title:null==p?void 0:p.title,sourceBranch:null==p?void 0:p.sourceBranch,targetBranch:null==p?void 0:p.targetBranch,author:null==p?void 0:p.author,changes:null==p?void 0:p.changes,description:null==p?void 0:p.description,webUrl:null==p?void 0:p.webUrl}]}})})()}},f={name:"git-commit",menu:{icon:n().createElement(o.NodeIndexOutlined,null),Component:function(){return n().createElement("span",null,"Git Commit")}},tag:{Component:function(e){var t=e.item;return n().createElement(r.Space,{size:4},n().createElement(o.NodeIndexOutlined,null),n().createElement("span",null,(null==t?void 0:t.title)||"Commit ".concat(null==t?void 0:t.uid)))}},getContent:function(e,t){var n=t.uid;return u(function(){var t,r,o,i,a,u,s;return c(this,function(c){switch(c.label){case 0:if(o=(r=l(String(n||"").split(":"),2))[0],i=r[1],!(a=Number(o))||!i)return[2,null];return[4,e.apiClient.request({url:"gitManager:commitDetail",params:{repositoryId:a,commitHash:i}})];case 1:return s=null==(u=c.sent())||null==(t=u.data)?void 0:t.data,[2,function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}({type:"git-commit",repositoryId:a,commitSha:i},s)]}})})()}},g=d(79),m=d.n(g),b=d(866);function y(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function h(e,t,n,r,o,i,a){try{var u=e[i](a),l=u.value}catch(e){n(e);return}u.done?t(l):Promise.resolve(l).then(r,o)}function w(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function a(e){h(i,r,o,a,u,"next",e)}function u(e){h(i,r,o,a,u,"throw",e)}a(void 0)})}}function O(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function S(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,o=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var i=[],a=!0,u=!1;try{for(o=o.call(e);!(a=(n=o.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){u=!0,r=e}finally{try{a||null==o.return||o.return()}finally{if(u)throw r}}return i}}(e,t)||x(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function j(e){return function(e){if(Array.isArray(e))return y(e)}(e)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||x(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function x(e,t){if(e){if("string"==typeof e)return y(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return y(e,t)}}function E(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),u=Object.defineProperty;return u(a,"next",{value:l(0)}),u(a,"throw",{value:l(1)}),u(a,"return",{value:l(2)}),"function"==typeof Symbol&&u(a,Symbol.iterator,{value:function(){return this}}),a;function l(u){return function(l){var c=[u,l];if(n)throw TypeError("Generator is already executing.");for(;a&&(a=0,c[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,r=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){i=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){i.label=c[1];break}if(6===c[0]&&i.label<o[1]){i.label=o[1],o=c;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(c);break}o[2]&&i.ops.pop(),i.trys.pop();continue}c=t.call(e,i)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var k=function(e){var o=e.activeRole,i=(0,b.useApp)().apiClient,a=S((0,t.useState)(!1),2),u=a[0],l=a[1],c=S((0,t.useState)([]),2),s=c[0],p=c[1],f=S((0,t.useState)({read:[],write:[]}),2),d=f[0],g=f[1];(0,t.useEffect)(function(){(null==o?void 0:o.name)&&m()},[null==o?void 0:o.name]);var m=function(){return w(function(){var e,t,n,a,u,c;return E(this,function(s){switch(s.label){case 0:l(!0),s.label=1;case 1:return s.trys.push([1,3,,4]),[4,Promise.all([i.request({resource:"gitRepositories",action:"list",params:{paginate:!1,sort:["name"]}}),i.request({url:"gitManager:rolePermissions",method:"get",params:{roleName:o.name}})])];case 2:return a=(n=S.apply(void 0,[s.sent(),2]))[0],c=(null==(u=n[1])||null==(e=u.data)?void 0:e.data)||(null==u?void 0:u.data)||{read:[],write:[]},p((null==a||null==(t=a.data)?void 0:t.data)||[]),g({read:c.read||[],write:c.write||[]}),[3,4];case 3:return console.error(s.sent()),r.message.error("Failed to load repository permissions"),[3,4];case 4:return l(!1),[2]}})})()},y=function(e,t,n){return w(function(){var a,u,l,c;return E(this,function(s){switch(s.label){case 0:var p,f;a=d[t]||[],u=n?j(new Set(j(a).concat([e]))):a.filter(function(t){return t!==e}),p=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){O(e,t,n[t])})}return e}({},d),f=null!=(f=O({},t,u))?f:{},Object.getOwnPropertyDescriptors?Object.defineProperties(p,Object.getOwnPropertyDescriptors(f)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t})(Object(f)).forEach(function(e){Object.defineProperty(p,e,Object.getOwnPropertyDescriptor(f,e))}),l=p,c=d,g(l),s.label=1;case 1:return s.trys.push([1,3,,4]),[4,i.request({url:"gitManager:updateRolePermissions",method:"post",data:{roleName:o.name,values:l}})];case 2:return s.sent(),[3,4];case 3:return s.sent(),r.message.error("Failed to update permissions"),g(c),[3,4];case 4:return[2]}})})()},h=[{title:"Repository Name",dataIndex:"name",key:"name",render:function(e){return n().createElement(r.Typography.Text,{strong:!0},e)}},{title:"Repository URL",dataIndex:"repoUrl",key:"repoUrl",ellipsis:!0,render:function(e){return n().createElement(r.Typography.Text,{type:"secondary"},e)}},{title:"Read (List, Browse Files, View History)",key:"read",width:100,render:function(e,t){return n().createElement(r.Checkbox,{checked:(d.read||[]).includes(t.id),onChange:function(e){return y(t.id,"read",e.target.checked)}})}},{title:"Write (Clone, Pull, Push, Review)",key:"write",width:100,render:function(e,t){return n().createElement(r.Checkbox,{checked:(d.write||[]).includes(t.id),onChange:function(e){return y(t.id,"write",e.target.checked)}})}}];return u&&!s.length?n().createElement(r.Spin,{style:{display:"block",margin:"40px auto"}}):n().createElement("div",{style:{padding:16}},n().createElement("div",{style:{marginBottom:16}},n().createElement(r.Typography.Text,{type:"secondary"},"Configure access permissions for each repository for the role"," ",n().createElement(r.Typography.Text,{strong:!0},(null==o?void 0:o.title)||(null==o?void 0:o.name)),".")),n().createElement(r.Table,{dataSource:s,columns:h,rowKey:"id",pagination:!1,size:"small",bordered:!0}))};function P(e,t,n,r,o,i,a){try{var u=e[i](a),l=u.value}catch(e){n(e);return}u.done?t(l):Promise.resolve(l).then(r,o)}function C(e,t,n){return(C=I()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&T(o,n.prototype),o}).apply(null,arguments)}function _(e){return(_=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function T(e,t){return(T=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function q(e){var t="function"==typeof Map?new Map:void 0;return(q=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return C(e,arguments,_(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),T(n,e)})(e)}function I(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(I=function(){return!!e})()}var M=n().lazy(function(){return Promise.all([d.e("326"),d.e("900")]).then(d.bind(d,591)).then(function(e){return{default:e.GitManagerSettings}})}),A=n().lazy(function(){return d.e("434").then(d.bind(d,33)).then(function(e){return{default:e.RepositoryConfigSettings}})}),R=n().lazy(function(){return d.e("156").then(d.bind(d,367)).then(function(e){return{default:e.GitAccountsSettings}})}),B=n().lazy(function(){return d.e("356").then(d.bind(d,935))}),N=function(e){var t;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function r(){var e,t;if(!(this instanceof r))throw TypeError("Cannot call a class as a function");return e=r,t=arguments,e=_(e),function(e,t){var n;if(t&&("object"==((n=t)&&"u">typeof Symbol&&n.constructor===Symbol?"symbol":typeof n)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,I()?Reflect.construct(e,t||[],_(this).constructor):e.apply(this,t))}return r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),e&&T(r,e),t=[{key:"load",value:function(){var e;return(e=function(){var e,t;return function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),u=Object.defineProperty;return u(a,"next",{value:l(0)}),u(a,"throw",{value:l(1)}),u(a,"return",{value:l(2)}),"function"==typeof Symbol&&u(a,Symbol.iterator,{value:function(){return this}}),a;function l(u){return function(l){var c=[u,l];if(n)throw TypeError("Generator is already executing.");for(;a&&(a=0,c[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,r=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){i=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){i.label=c[1];break}if(6===c[0]&&i.label<o[1]){i.label=o[1],o=c;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(c);break}o[2]&&i.ops.pop(),i.trys.pop();continue}c=t.call(e,i)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}(this,function(r){return this.app.pluginSettingsManager.add("git-manager",{title:this.t("Git Manager"),icon:"BranchesOutlined"}),this.app.pluginSettingsManager.add("git-manager.repositories",{title:this.t("Repositories"),Component:A,aclSnippet:"pm.plugin-git-manager.repositories"}),this.app.pluginSettingsManager.add("git-manager.accounts",{title:this.t("Git Accounts"),Component:R,aclSnippet:"pm.plugin-git-manager.repositories"}),this.app.pluginSettingsManager.add("git-manager.subtree-splits",{title:this.t("Subtree Splits"),Component:B,aclSnippet:"pm.plugin-git-manager.write"}),this.app.pluginSettingsManager.add("git-manager.manage",{title:this.t("Manage"),Component:M,aclSnippet:"pm.plugin-git-manager.manage"}),(null==(e=this.app.aiManager)?void 0:e.registerWorkContext)&&(e.registerWorkContext("git-repository",s),e.registerWorkContext("git-merge-request",p),e.registerWorkContext("git-commit",f)),(t=this.app.pm.get(m()))&&t.settingsUI.addPermissionsTab(function(e){e.t;var t=e.TabLayout,r=e.activeRole;return{key:"git-manager",label:"Git Manager",sort:25,children:n().createElement(t,null,n().createElement(k,{activeRole:r}))}}),[2]})},function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function a(e){P(i,r,o,a,u,"next",e)}function u(e){P(i,r,o,a,u,"throw",e)}a(void 0)})}).call(this)}}],function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(r.prototype,t),r}(q(e.Plugin)),G=N}(),v}()});
|
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
"use strict";(self.webpackChunkplugin_git_manager_client_v2=self.webpackChunkplugin_git_manager_client_v2||[]).push([["434"],{33:function(e,t,r){r.d(t,{RepositoryConfig:function(){return h}});var n=r(155),a=r.n(n),l=r(59),o=r(375),u=r(485),i=r(602),c=r(578);function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function d(e,t,r,n,a,l,o){try{var u=e[l](o),i=u.value}catch(e){r(e);return}u.done?t(i):Promise.resolve(i).then(n,a)}function f(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var l=e.apply(t,r);function o(e){d(l,n,a,o,u,"next",e)}function u(e){d(l,n,a,o,u,"throw",e)}o(void 0)})}}function p(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,a=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=a){var l=[],o=!0,u=!1;try{for(a=a.call(e);!(o=(r=a.next()).done)&&(l.push(r.value),!t||l.length!==t);o=!0);}catch(e){u=!0,n=e}finally{try{o||null==a.return||a.return()}finally{if(u)throw n}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return s(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return s(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function m(e,t){var r,n,a,l={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),u=Object.defineProperty;return u(o,"next",{value:i(0)}),u(o,"throw",{value:i(1)}),u(o,"return",{value:i(2)}),"function"==typeof Symbol&&u(o,Symbol.iterator,{value:function(){return this}}),o;function i(u){return function(i){var c=[u,i];if(r)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(l=0)),l;)try{if(r=1,n&&(a=2&c[0]?n.return:c[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,c[1])).done)return a;switch(n=0,a&&(c=[2&c[0],a.value]),c[0]){case 0:case 1:a=c;break;case 4:return l.label++,{value:c[1],done:!1};case 5:l.label++,n=c[1],c=[0];continue;case 7:c=l.ops.pop(),l.trys.pop();continue;default:if(!(a=(a=l.trys).length>0&&a[a.length-1])&&(6===c[0]||2===c[0])){l=0;continue}if(3===c[0]&&(!a||c[1]>a[0]&&c[1]<a[3])){l.label=c[1];break}if(6===c[0]&&l.label<a[1]){l.label=a[1],a=c;break}if(a&&l.label<a[2]){l.label=a[2],l.ops.push(c);break}a[2]&&l.ops.pop(),l.trys.pop();continue}c=t.call(e,l)}catch(e){c=[6,e],n=0}finally{r=a=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var h=function(){var e=(0,c.k)(),t=(0,u.useApp)().apiClient,r=(0,i.B)(),s=r.repos,d=r.refreshRepos,h=r.selectedRepo,y=r.setSelectedRepo,v=p((0,n.useState)(!1),2),b=v[0],g=v[1],w=p((0,n.useState)(null),2),E=w[0],I=w[1],S=p(l.Form.useForm(),1)[0],R=p((0,n.useState)(null),2),k=R[0],C=R[1],A=p((0,n.useState)([]),2),F=A[0],O=A[1],x=p((0,n.useState)([]),2),P=x[0],j=x[1],B=(0,n.useCallback)(function(){return f(function(){var e;return m(this,function(r){switch(r.label){case 0:return[4,t.request({url:"gitReviewFlows:list",params:{pageSize:100,filter:{enabled:!0,triggerMode:{$in:["onMergeRequestCreated","both"]}}}})];case 1:return O((null==(e=r.sent().data)?void 0:e.data)||[]),[2]}})})()},[t]),q=(0,n.useCallback)(function(){return f(function(){var e;return m(this,function(r){switch(r.label){case 0:return[4,t.request({url:"gitAccounts:list",params:{pageSize:100}})];case 1:return j((null==(e=r.sent().data)?void 0:e.data)||[]),[2]}})})()},[t]);(0,n.useEffect)(function(){B().catch(function(){}),q().catch(function(){})},[B,q]),(0,n.useEffect)(function(){d().catch(function(){})},[d]);var T=function(t){return F.filter(function(e){return e.repositoryId===t||null==e.repositoryId}).map(function(t){return{value:t.id,label:"".concat(t.name).concat(null==t.repositoryId?" (".concat(e("global"),")"):"")}})},z=[{title:e("Repository Name"),dataIndex:"name",key:"name",render:function(e,t){return a().createElement("a",{onClick:function(){return y(t)}},e)}},{title:e("Repository URL"),dataIndex:"repoUrl",key:"repoUrl",ellipsis:!0},{title:e("Git Account"),dataIndex:"gitAccountId",key:"gitAccountId",width:160,render:function(t){if(!t)return a().createElement(l.Tag,null,e("None"));var r=P.find(function(e){return e.id===t});return r?r.name:a().createElement(l.Tag,null,e("None"))}},{title:e("Local Path"),dataIndex:"localPath",key:"localPath",ellipsis:!0},{title:e("Default Branch"),dataIndex:"defaultBranch",key:"defaultBranch",width:120},{title:a().createElement(l.Tooltip,{title:e("Auto-poll new merge requests every 5 minutes")},a().createElement(l.Space,{size:4},a().createElement(o.RobotOutlined,null),e("Auto Review"))),dataIndex:"autoReview",key:"autoReview",width:110,render:function(r,n){return a().createElement(l.Switch,{size:"small",checked:!!r,onChange:function(r){return f(function(){var a,o,u,i;return m(this,function(c){switch(c.label){case 0:return c.trys.push([0,3,,4]),u=T(n.id),[4,t.request({url:"gitRepositories:update",method:"post",params:{filterByTk:n.id},data:{autoReview:r,autoReviewFlowId:r&&!n.autoReviewFlowId?null!=(a=null==(o=u[0])?void 0:o.value)?a:null:n.autoReviewFlowId}})];case 1:return c.sent(),[4,d()];case 2:return c.sent(),[3,4];case 3:return i=c.sent(),l.message.error((null==i?void 0:i.message)||e("Failed to save")),[3,4];case 4:return[2]}})})()}})}},{title:e("Primary Auto Flow"),dataIndex:"autoReviewFlowId",key:"autoReviewFlowId",width:220,render:function(r,n){var o=T(n.id);return a().createElement(l.Select,{allowClear:!0,size:"small",style:{width:"100%"},disabled:!n.autoReview,placeholder:e("Select a flow"),value:r||void 0,options:o,notFoundContent:e("No matching flow available"),onChange:function(r){return f(function(){var a;return m(this,function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),[4,t.request({url:"gitRepositories:update",method:"post",params:{filterByTk:n.id},data:{autoReviewFlowId:r||null}})];case 1:return o.sent(),[4,d()];case 2:return o.sent(),[3,4];case 3:return a=o.sent(),l.message.error((null==a?void 0:a.message)||e("Failed to save")),[3,4];case 4:return[2]}})})()}})}},{title:e("Status"),dataIndex:"status",key:"status",width:120,render:function(t){var r={connected:{color:"green",label:e("Connected")},error:{color:"red",label:e("Error")}}[t]||{color:"default",label:e("Disconnected")};return a().createElement(l.Tag,{color:r.color},r.label)}},{title:"",key:"actions",width:200,render:function(r,n){return a().createElement(l.Space,{size:"small"},"connected"!==n.status&&a().createElement(l.Button,{size:"small",icon:a().createElement(o.LinkOutlined,null),loading:k==="clone-".concat(n.id),onClick:function(){return f(function(){var r,a,o,u,i;return m(this,function(c){switch(c.label){case 0:C("clone-".concat(n.id)),c.label=1;case 1:return c.trys.push([1,4,5,6]),[4,t.request({url:"gitManager:clone",method:"post",params:{repositoryId:n.id}})];case 2:return c.sent(),l.message.success(e("Clone successful")),[4,d()];case 3:return c.sent(),[3,6];case 4:return r=c.sent(),l.message.error((null==r||null==(i=r.response)||null==(u=i.data)||null==(o=u.errors)||null==(a=o[0])?void 0:a.message)||e("Clone failed")),[3,6];case 5:return C(null),[7];case 6:return[2]}})})()}},e("Clone")),a().createElement(l.Button,{size:"small",onClick:function(){I(n),S.setFieldsValue(n),g(!0)}},e("Edit")),a().createElement(l.Popconfirm,{title:e("Delete this repository?"),onConfirm:function(){var r;return r=n.id,f(function(){return m(this,function(n){switch(n.label){case 0:return[4,t.request({url:"gitRepositories:destroy",method:"post",params:{filterByTk:r}})];case 1:return n.sent(),(null==h?void 0:h.id)===r&&y(null),l.message.success(e("Deleted")),[4,d()];case 2:return n.sent(),[2]}})})()}},a().createElement(l.Button,{size:"small",danger:!0,icon:a().createElement(o.DeleteOutlined,null)})))}}];return a().createElement("div",null,a().createElement("div",{style:{marginBottom:16}},a().createElement(l.Button,{type:"primary",icon:a().createElement(o.PlusOutlined,null),onClick:function(){I(null),S.resetFields(),g(!0)}},e("Add Repository"))),a().createElement(l.Table,{dataSource:s,columns:z,rowKey:"id",size:"small",pagination:!1,rowClassName:function(e){return(null==h?void 0:h.id)===e.id?"ant-table-row-selected":""}}),a().createElement(l.Modal,{title:E?e("Edit Repository"):e("Add Repository"),open:b,onOk:function(){return f(function(){var r,n;return m(this,function(a){switch(a.label){case 0:return[4,S.validateFields()];case 1:r=a.sent(),a.label=2;case 2:if(a.trys.push([2,8,,9]),!E)return[3,4];return[4,t.request({url:"gitRepositories:update",method:"post",params:{filterByTk:E.id},data:r})];case 3:return a.sent(),l.message.success(e("Repository updated")),[3,6];case 4:return[4,t.request({url:"gitRepositories:create",method:"post",data:r})];case 5:a.sent(),l.message.success(e("Repository added")),a.label=6;case 6:return g(!1),I(null),S.resetFields(),[4,d()];case 7:return a.sent(),[3,9];case 8:return n=a.sent(),l.message.error((null==n?void 0:n.message)||e("Failed to save")),[3,9];case 9:return[2]}})})()},onCancel:function(){g(!1),I(null)},width:520},a().createElement(l.Form,{form:S,layout:"vertical",initialValues:{defaultBranch:"main"}},a().createElement(l.Form.Item,{name:"name",label:e("Repository Name"),rules:[{required:!0}]},a().createElement(l.Input,{placeholder:"my-project"})),a().createElement(l.Form.Item,{name:"repoUrl",label:e("Repository URL"),rules:[{required:!0}]},a().createElement(l.Input,{placeholder:"https://gitlab.com/user/repo.git"})),a().createElement(l.Form.Item,{name:"gitAccountId",label:e("Git Account"),rules:[{required:!0,message:e("Please select a Git account")}],extra:e("Select the GitLab or GitHub account to use for this repository")},a().createElement(l.Select,{placeholder:e("Select an account"),options:P.map(function(e){return{value:e.id,label:"".concat(e.name," (").concat(e.username,")")}}),notFoundContent:e("No accounts configured. Add one in the Git Accounts tab.")})),a().createElement(l.Form.Item,{name:"localPath",label:e("Local Path"),rules:[{required:!0}]},a().createElement(l.Input,{placeholder:"my-project"})),a().createElement(l.Form.Item,{name:"defaultBranch",label:e("Default Branch")},a().createElement(l.Input,{placeholder:"main"})),a().createElement(l.Form.Item,{name:"autoReviewFlowId",label:e("Primary Auto Review Flow"),extra:e("Only flows with automatic trigger modes are shown")},a().createElement(l.Select,{allowClear:!0,placeholder:e("Select a flow"),options:T(null==E?void 0:E.id),notFoundContent:e("No matching flow available")})))))}},602:function(e,t,r){r.d(t,{B:function(){return f},N:function(){return p}});var n=r(155),a=r.n(n),l=r(485);function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function u(e,t,r,n,a,l,o){try{var u=e[l](o),i=u.value}catch(e){r(e);return}u.done?t(i):Promise.resolve(i).then(n,a)}function i(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var l=e.apply(t,r);function o(e){u(l,n,a,o,i,"next",e)}function i(e){u(l,n,a,o,i,"throw",e)}o(void 0)})}}function c(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,a=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=a){var l=[],o=!0,u=!1;try{for(a=a.call(e);!(o=(r=a.next()).done)&&(l.push(r.value),!t||l.length!==t);o=!0);}catch(e){u=!0,n=e}finally{try{o||null==a.return||a.return()}finally{if(u)throw n}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return o(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return o(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e,t){var r,n,a,l={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),u=Object.defineProperty;return u(o,"next",{value:i(0)}),u(o,"throw",{value:i(1)}),u(o,"return",{value:i(2)}),"function"==typeof Symbol&&u(o,Symbol.iterator,{value:function(){return this}}),o;function i(u){return function(i){var c=[u,i];if(r)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(l=0)),l;)try{if(r=1,n&&(a=2&c[0]?n.return:c[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,c[1])).done)return a;switch(n=0,a&&(c=[2&c[0],a.value]),c[0]){case 0:case 1:a=c;break;case 4:return l.label++,{value:c[1],done:!1};case 5:l.label++,n=c[1],c=[0];continue;case 7:c=l.ops.pop(),l.trys.pop();continue;default:if(!(a=(a=l.trys).length>0&&a[a.length-1])&&(6===c[0]||2===c[0])){l=0;continue}if(3===c[0]&&(!a||c[1]>a[0]&&c[1]<a[3])){l.label=c[1];break}if(6===c[0]&&l.label<a[1]){l.label=a[1],a=c;break}if(a&&l.label<a[2]){l.label=a[2],l.ops.push(c);break}a[2]&&l.ops.pop(),l.trys.pop();continue}c=t.call(e,l)}catch(e){c=[6,e],n=0}finally{r=a=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var d=(0,n.createContext)(null);function f(){var e=(0,n.useContext)(d);if(!e)throw Error("useGitManager must be used within GitManagerProvider");return e}var p=function(e){var t=e.children,r=(0,l.useApp)().apiClient,o=c((0,n.useState)([]),2),u=o[0],f=o[1],p=c((0,n.useState)(null),2),m=p[0],h=p[1],y=c((0,n.useState)(!1),2),v=y[0],b=y[1],g=c((0,n.useState)([]),2),w=g[0],E=g[1],I=c((0,n.useState)(""),2),S=I[0],R=I[1],k=(0,n.useRef)(m);k.current=m;var C=(0,n.useCallback)(function(){return i(function(){var e,t,n,a;return s(this,function(l){switch(l.label){case 0:if(!(e=k.current)||"connected"!==e.status)return E([]),R(""),[2];l.label=1;case 1:return l.trys.push([1,3,,4]),[4,r.request({url:"gitManager:branches",params:{repositoryId:e.id}})];case 2:return(a=(null==(n=l.sent().data)||null==(t=n.data)?void 0:t.data)||(null==n?void 0:n.data))&&(E(a.all||[]),R(a.current||"")),[3,4];case 3:return l.sent(),E([]),R(""),[3,4];case 4:return[2]}})})()},[r]),A=(0,n.useCallback)(function(){return i(function(){var e,t,n,a;return s(this,function(l){switch(l.label){case 0:b(!0),l.label=1;case 1:return l.trys.push([1,,3,4]),[4,r.request({url:"gitRepositories:list",params:{pageSize:100}})];case 2:return f(t=(null==(e=l.sent().data)?void 0:e.data)||[]),(n=k.current)&&(a=t.find(function(e){return e.id===n.id}))&&h(a),[3,4];case 3:return b(!1),[7];case 4:return[2]}})})()},[r]);return a().createElement(d.Provider,{value:{repos:u,selectedRepo:m,loading:v,branches:w,currentBranch:S,setSelectedRepo:h,refreshRepos:A,refreshBranches:C}},t)}},578:function(e,t,r){r.d(t,{k:function(){return a}});var n=r(485);function a(){var e=(0,n.useApp)();return function(t,r){return e.i18n.t(t,function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){var n;n=r[t],t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n})}return e}({ns:["plugin-git-manager","client"]},r))}}}}]);
|
|
10
|
+
"use strict";(self.webpackChunkplugin_git_manager_client_v2=self.webpackChunkplugin_git_manager_client_v2||[]).push([["434"],{33:function(e,t,r){r.d(t,{RepositoryConfig:function(){return h}});var n=r(155),a=r.n(n),l=r(59),o=r(375),u=r(485),i=r(602),c=r(578);function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function d(e,t,r,n,a,l,o){try{var u=e[l](o),i=u.value}catch(e){r(e);return}u.done?t(i):Promise.resolve(i).then(n,a)}function f(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var l=e.apply(t,r);function o(e){d(l,n,a,o,u,"next",e)}function u(e){d(l,n,a,o,u,"throw",e)}o(void 0)})}}function p(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,a=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=a){var l=[],o=!0,u=!1;try{for(a=a.call(e);!(o=(r=a.next()).done)&&(l.push(r.value),!t||l.length!==t);o=!0);}catch(e){u=!0,n=e}finally{try{o||null==a.return||a.return()}finally{if(u)throw n}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return s(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return s(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function m(e,t){var r,n,a,l={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),u=Object.defineProperty;return u(o,"next",{value:i(0)}),u(o,"throw",{value:i(1)}),u(o,"return",{value:i(2)}),"function"==typeof Symbol&&u(o,Symbol.iterator,{value:function(){return this}}),o;function i(u){return function(i){var c=[u,i];if(r)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(l=0)),l;)try{if(r=1,n&&(a=2&c[0]?n.return:c[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,c[1])).done)return a;switch(n=0,a&&(c=[2&c[0],a.value]),c[0]){case 0:case 1:a=c;break;case 4:return l.label++,{value:c[1],done:!1};case 5:l.label++,n=c[1],c=[0];continue;case 7:c=l.ops.pop(),l.trys.pop();continue;default:if(!(a=(a=l.trys).length>0&&a[a.length-1])&&(6===c[0]||2===c[0])){l=0;continue}if(3===c[0]&&(!a||c[1]>a[0]&&c[1]<a[3])){l.label=c[1];break}if(6===c[0]&&l.label<a[1]){l.label=a[1],a=c;break}if(a&&l.label<a[2]){l.label=a[2],l.ops.push(c);break}a[2]&&l.ops.pop(),l.trys.pop();continue}c=t.call(e,l)}catch(e){c=[6,e],n=0}finally{r=a=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var h=function(){var e=(0,c.k)(),t=(0,u.useApp)().apiClient,r=(0,i.B)(),s=r.repos,d=r.refreshRepos,h=r.selectedRepo,y=r.setSelectedRepo,v=p((0,n.useState)(!1),2),b=v[0],g=v[1],w=p((0,n.useState)(null),2),E=w[0],S=w[1],I=p(l.Form.useForm(),1)[0],R=p((0,n.useState)(null),2),k=R[0],C=R[1],A=p((0,n.useState)([]),2),F=A[0],x=A[1],O=p((0,n.useState)([]),2),P=O[0],j=O[1],B=(0,n.useCallback)(function(){return f(function(){var e;return m(this,function(r){switch(r.label){case 0:return[4,t.request({url:"gitReviewFlows:list",params:{pageSize:100,filter:{enabled:!0,triggerMode:{$in:["onMergeRequestCreated","both"]}}}})];case 1:return x((null==(e=r.sent().data)?void 0:e.data)||[]),[2]}})})()},[t]),q=(0,n.useCallback)(function(){return f(function(){var e;return m(this,function(r){switch(r.label){case 0:return[4,t.request({url:"gitAccounts:list",params:{pageSize:100}})];case 1:return j((null==(e=r.sent().data)?void 0:e.data)||[]),[2]}})})()},[t]);(0,n.useEffect)(function(){B().catch(function(){}),q().catch(function(){})},[B,q]),(0,n.useEffect)(function(){d().catch(function(){})},[d]);var T=function(t){return F.filter(function(e){return e.repositoryId===t||null==e.repositoryId}).map(function(t){return{value:t.id,label:"".concat(t.name).concat(null==t.repositoryId?" (".concat(e("global"),")"):"")}})},z=[{title:e("Repository Name"),dataIndex:"name",key:"name",render:function(e,t){return a().createElement("a",{onClick:function(){return y(t)}},e)}},{title:e("Repository URL"),dataIndex:"repoUrl",key:"repoUrl",ellipsis:!0},{title:e("Git Account"),dataIndex:"gitAccountId",key:"gitAccountId",width:160,render:function(t){if(!t)return a().createElement(l.Tag,null,e("None"));var r=P.find(function(e){return e.id===t});return r?r.name:a().createElement(l.Tag,null,e("None"))}},{title:e("Local Path"),dataIndex:"localPath",key:"localPath",ellipsis:!0},{title:e("Default Branch"),dataIndex:"defaultBranch",key:"defaultBranch",width:120},{title:a().createElement(l.Tooltip,{title:e("Auto-poll new merge requests every 5 minutes")},a().createElement(l.Space,{size:4},a().createElement(o.RobotOutlined,null),e("Auto Review"))),dataIndex:"autoReview",key:"autoReview",width:110,render:function(r,n){return a().createElement(l.Switch,{size:"small",checked:!!r,onChange:function(r){return f(function(){var a,o,u,i;return m(this,function(c){switch(c.label){case 0:return c.trys.push([0,3,,4]),u=T(n.id),[4,t.request({url:"gitRepositories:update",method:"post",params:{filterByTk:n.id},data:{autoReview:r,autoReviewFlowId:r&&!n.autoReviewFlowId?null!=(a=null==(o=u[0])?void 0:o.value)?a:null:n.autoReviewFlowId}})];case 1:return c.sent(),[4,d()];case 2:return c.sent(),[3,4];case 3:return i=c.sent(),l.message.error((null==i?void 0:i.message)||e("Failed to save")),[3,4];case 4:return[2]}})})()}})}},{title:e("Primary Auto Flow"),dataIndex:"autoReviewFlowId",key:"autoReviewFlowId",width:220,render:function(r,n){var o=T(n.id);return a().createElement(l.Select,{allowClear:!0,size:"small",style:{width:"100%"},disabled:!n.autoReview,placeholder:e("Select a flow"),value:r||void 0,options:o,notFoundContent:e("No matching flow available"),onChange:function(r){return f(function(){var a;return m(this,function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),[4,t.request({url:"gitRepositories:update",method:"post",params:{filterByTk:n.id},data:{autoReviewFlowId:r||null}})];case 1:return o.sent(),[4,d()];case 2:return o.sent(),[3,4];case 3:return a=o.sent(),l.message.error((null==a?void 0:a.message)||e("Failed to save")),[3,4];case 4:return[2]}})})()}})}},{title:e("Status"),dataIndex:"status",key:"status",width:120,render:function(t){var r={connected:{color:"green",label:e("Connected")},error:{color:"red",label:e("Error")}}[t]||{color:"default",label:e("Disconnected")};return a().createElement(l.Tag,{color:r.color},r.label)}},{title:"",key:"actions",width:200,render:function(r,n){return a().createElement(l.Space,{size:"small"},"connected"!==n.status&&a().createElement(l.Button,{size:"small",icon:a().createElement(o.LinkOutlined,null),loading:k==="clone-".concat(n.id),onClick:function(){return f(function(){var r,a,o,u,i;return m(this,function(c){switch(c.label){case 0:C("clone-".concat(n.id)),c.label=1;case 1:return c.trys.push([1,4,5,6]),[4,t.request({url:"gitManager:clone",method:"post",params:{repositoryId:n.id}})];case 2:return c.sent(),l.message.success(e("Clone successful")),[4,d()];case 3:return c.sent(),[3,6];case 4:return r=c.sent(),l.message.error((null==r||null==(i=r.response)||null==(u=i.data)||null==(o=u.errors)||null==(a=o[0])?void 0:a.message)||e("Clone failed")),[3,6];case 5:return C(null),[7];case 6:return[2]}})})()}},e("Clone")),a().createElement(l.Button,{size:"small",onClick:function(){S(n),I.setFieldsValue(n),g(!0)}},e("Edit")),a().createElement(l.Popconfirm,{title:e("Delete this repository?"),onConfirm:function(){var r;return r=n.id,f(function(){return m(this,function(n){switch(n.label){case 0:return[4,t.request({url:"gitRepositories:destroy",method:"post",params:{filterByTk:r}})];case 1:return n.sent(),(null==h?void 0:h.id)===r&&y(null),l.message.success(e("Deleted")),[4,d()];case 2:return n.sent(),[2]}})})()}},a().createElement(l.Button,{size:"small",danger:!0,icon:a().createElement(o.DeleteOutlined,null)})))}}];return a().createElement("div",null,a().createElement("div",{style:{marginBottom:16}},a().createElement(l.Button,{type:"primary",icon:a().createElement(o.PlusOutlined,null),onClick:function(){S(null),I.resetFields(),g(!0)}},e("Add Repository"))),a().createElement(l.Table,{dataSource:s,columns:z,rowKey:"id",size:"small",pagination:!1,rowClassName:function(e){return(null==h?void 0:h.id)===e.id?"ant-table-row-selected":""}}),a().createElement(l.Modal,{title:E?e("Edit Repository"):e("Add Repository"),open:b,onOk:function(){return f(function(){var r,n;return m(this,function(a){switch(a.label){case 0:return[4,I.validateFields()];case 1:r=a.sent(),a.label=2;case 2:if(a.trys.push([2,8,,9]),!E)return[3,4];return[4,t.request({url:"gitRepositories:update",method:"post",params:{filterByTk:E.id},data:r})];case 3:return a.sent(),l.message.success(e("Repository updated")),[3,6];case 4:return[4,t.request({url:"gitRepositories:create",method:"post",data:r})];case 5:a.sent(),l.message.success(e("Repository added")),a.label=6;case 6:return g(!1),S(null),I.resetFields(),[4,d()];case 7:return a.sent(),[3,9];case 8:return n=a.sent(),l.message.error((null==n?void 0:n.message)||e("Failed to save")),[3,9];case 9:return[2]}})})()},onCancel:function(){g(!1),S(null)},width:520},a().createElement(l.Form,{form:I,layout:"vertical",initialValues:{defaultBranch:"main",registryExportEnabled:!1}},a().createElement(l.Form.Item,{name:"name",label:e("Repository Name"),rules:[{required:!0}]},a().createElement(l.Input,{placeholder:"my-project"})),a().createElement(l.Form.Item,{name:"repoUrl",label:e("Repository URL"),rules:[{required:!0}]},a().createElement(l.Input,{placeholder:"https://gitlab.com/user/repo.git"})),a().createElement(l.Form.Item,{name:"gitAccountId",label:e("Git Account"),rules:[{required:!0,message:e("Please select a Git account")}],extra:e("Select the GitLab or GitHub account to use for this repository")},a().createElement(l.Select,{placeholder:e("Select an account"),options:P.map(function(e){return{value:e.id,label:"".concat(e.name," (").concat(e.username,")")}}),notFoundContent:e("No accounts configured. Add one in the Git Accounts tab.")})),a().createElement(l.Form.Item,{name:"localPath",label:e("Local Path"),rules:[{required:!0}]},a().createElement(l.Input,{placeholder:"my-project"})),a().createElement(l.Form.Item,{name:"defaultBranch",label:e("Default Branch")},a().createElement(l.Input,{placeholder:"main"})),a().createElement(l.Form.Item,{name:"registryExportEnabled",label:e("Allow Skill Registry export"),valuePropName:"checked"},a().createElement(l.Switch,null)),a().createElement(l.Form.Item,{name:"autoReviewFlowId",label:e("Primary Auto Review Flow"),extra:e("Only flows with automatic trigger modes are shown")},a().createElement(l.Select,{allowClear:!0,placeholder:e("Select a flow"),options:T(null==E?void 0:E.id),notFoundContent:e("No matching flow available")})))))}},602:function(e,t,r){r.d(t,{B:function(){return f},N:function(){return p}});var n=r(155),a=r.n(n),l=r(485);function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function u(e,t,r,n,a,l,o){try{var u=e[l](o),i=u.value}catch(e){r(e);return}u.done?t(i):Promise.resolve(i).then(n,a)}function i(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var l=e.apply(t,r);function o(e){u(l,n,a,o,i,"next",e)}function i(e){u(l,n,a,o,i,"throw",e)}o(void 0)})}}function c(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,a=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=a){var l=[],o=!0,u=!1;try{for(a=a.call(e);!(o=(r=a.next()).done)&&(l.push(r.value),!t||l.length!==t);o=!0);}catch(e){u=!0,n=e}finally{try{o||null==a.return||a.return()}finally{if(u)throw n}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return o(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return o(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e,t){var r,n,a,l={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),u=Object.defineProperty;return u(o,"next",{value:i(0)}),u(o,"throw",{value:i(1)}),u(o,"return",{value:i(2)}),"function"==typeof Symbol&&u(o,Symbol.iterator,{value:function(){return this}}),o;function i(u){return function(i){var c=[u,i];if(r)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(l=0)),l;)try{if(r=1,n&&(a=2&c[0]?n.return:c[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,c[1])).done)return a;switch(n=0,a&&(c=[2&c[0],a.value]),c[0]){case 0:case 1:a=c;break;case 4:return l.label++,{value:c[1],done:!1};case 5:l.label++,n=c[1],c=[0];continue;case 7:c=l.ops.pop(),l.trys.pop();continue;default:if(!(a=(a=l.trys).length>0&&a[a.length-1])&&(6===c[0]||2===c[0])){l=0;continue}if(3===c[0]&&(!a||c[1]>a[0]&&c[1]<a[3])){l.label=c[1];break}if(6===c[0]&&l.label<a[1]){l.label=a[1],a=c;break}if(a&&l.label<a[2]){l.label=a[2],l.ops.push(c);break}a[2]&&l.ops.pop(),l.trys.pop();continue}c=t.call(e,l)}catch(e){c=[6,e],n=0}finally{r=a=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var d=(0,n.createContext)(null);function f(){var e=(0,n.useContext)(d);if(!e)throw Error("useGitManager must be used within GitManagerProvider");return e}var p=function(e){var t=e.children,r=(0,l.useApp)().apiClient,o=c((0,n.useState)([]),2),u=o[0],f=o[1],p=c((0,n.useState)(null),2),m=p[0],h=p[1],y=c((0,n.useState)(!1),2),v=y[0],b=y[1],g=c((0,n.useState)([]),2),w=g[0],E=g[1],S=c((0,n.useState)(""),2),I=S[0],R=S[1],k=(0,n.useRef)(m);k.current=m;var C=(0,n.useCallback)(function(){return i(function(){var e,t,n,a;return s(this,function(l){switch(l.label){case 0:if(!(e=k.current)||"connected"!==e.status)return E([]),R(""),[2];l.label=1;case 1:return l.trys.push([1,3,,4]),[4,r.request({url:"gitManager:branches",params:{repositoryId:e.id}})];case 2:return(a=(null==(n=l.sent().data)||null==(t=n.data)?void 0:t.data)||(null==n?void 0:n.data))&&(E(a.all||[]),R(a.current||"")),[3,4];case 3:return l.sent(),E([]),R(""),[3,4];case 4:return[2]}})})()},[r]),A=(0,n.useCallback)(function(){return i(function(){var e,t,n,a;return s(this,function(l){switch(l.label){case 0:b(!0),l.label=1;case 1:return l.trys.push([1,,3,4]),[4,r.request({url:"gitRepositories:list",params:{pageSize:100}})];case 2:return f(t=(null==(e=l.sent().data)?void 0:e.data)||[]),(n=k.current)&&(a=t.find(function(e){return e.id===n.id}))&&h(a),[3,4];case 3:return b(!1),[7];case 4:return[2]}})})()},[r]);return a().createElement(d.Provider,{value:{repos:u,selectedRepo:m,loading:v,branches:w,currentBranch:I,setSelectedRepo:h,refreshRepos:A,refreshBranches:C}},t)}},578:function(e,t,r){r.d(t,{k:function(){return a}});var n=r(485);function a(){var e=(0,n.useApp)();return function(t,r){return e.i18n.t(t,function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){var n;n=r[t],t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n})}return e}({ns:["plugin-git-manager","client"]},r))}}}}]);
|
package/dist/client-v2/index.js
CHANGED
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@nocobase/client-v2"),require("react"),require("antd"),require("@ant-design/icons"),require("@nocobase/flow-engine"),require("@nocobase/plugin-ai/client")):"function"==typeof define&&define.amd?define("plugin-git-manager/client-v2",["@nocobase/client-v2","react","antd","@ant-design/icons","@nocobase/flow-engine","@nocobase/plugin-ai/client"],t):"object"==typeof exports?exports["plugin-git-manager/client-v2"]=t(require("@nocobase/client-v2"),require("react"),require("antd"),require("@ant-design/icons"),require("@nocobase/flow-engine"),require("@nocobase/plugin-ai/client")):e["plugin-git-manager/client-v2"]=t(e["@nocobase/client-v2"],e.react,e.antd,e["@ant-design/icons"],e["@nocobase/flow-engine"],e["@nocobase/plugin-ai/client"])}(self,function(e,t,n,r,o,i){return function(){"use strict";var a,u,c,l={375:function(e){e.exports=r},485:function(t){t.exports=e},694:function(e){e.exports=o},75:function(e){e.exports=i},59:function(e){e.exports=n},155:function(e){e.exports=t}},p={};function s(e){var t=p[e];if(void 0!==t)return t.exports;var n=p[e]={exports:{}};return l[e].call(n.exports,n,n.exports,s),n.exports}s.m=l,s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,{a:t}),t},s.d=function(e,t){for(var n in t)s.o(t,n)&&!s.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},s.f={},s.e=function(e){return Promise.all(Object.keys(s.f).reduce(function(t,n){return s.f[n](e,t),t},[]))},s.u=function(e){return""+e+"."+({326:"42b7b53651ffab3a",356:"3d40a34bad08f8ff",434:"
|
|
10
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@nocobase/client-v2"),require("react"),require("antd"),require("@ant-design/icons"),require("@nocobase/flow-engine"),require("@nocobase/plugin-ai/client")):"function"==typeof define&&define.amd?define("plugin-git-manager/client-v2",["@nocobase/client-v2","react","antd","@ant-design/icons","@nocobase/flow-engine","@nocobase/plugin-ai/client"],t):"object"==typeof exports?exports["plugin-git-manager/client-v2"]=t(require("@nocobase/client-v2"),require("react"),require("antd"),require("@ant-design/icons"),require("@nocobase/flow-engine"),require("@nocobase/plugin-ai/client")):e["plugin-git-manager/client-v2"]=t(e["@nocobase/client-v2"],e.react,e.antd,e["@ant-design/icons"],e["@nocobase/flow-engine"],e["@nocobase/plugin-ai/client"])}(self,function(e,t,n,r,o,i){return function(){"use strict";var a,u,c,l={375:function(e){e.exports=r},485:function(t){t.exports=e},694:function(e){e.exports=o},75:function(e){e.exports=i},59:function(e){e.exports=n},155:function(e){e.exports=t}},p={};function s(e){var t=p[e];if(void 0!==t)return t.exports;var n=p[e]={exports:{}};return l[e].call(n.exports,n,n.exports,s),n.exports}s.m=l,s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,{a:t}),t},s.d=function(e,t){for(var n in t)s.o(t,n)&&!s.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},s.f={},s.e=function(e){return Promise.all(Object.keys(s.f).reduce(function(t,n){return s.f[n](e,t),t},[]))},s.u=function(e){return""+e+"."+({326:"42b7b53651ffab3a",356:"3d40a34bad08f8ff",434:"7a27051db18526c0",900:"bef1c41d267e50c5"})[e]+".js"},s.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},f={},s.l=function(e,t,n,r){if(f[e])return void f[e].push(t);if(void 0!==n)for(var o,i,a=document.getElementsByTagName("script"),u=0;u<a.length;u++){var c=a[u];if(c.getAttribute("src")==e||c.getAttribute("data-rspack")=="plugin-git-manager/client-v2:"+n){o=c;break}}o||(i=!0,(o=document.createElement("script")).timeout=120,s.nc&&o.setAttribute("nonce",s.nc),o.setAttribute("data-rspack","plugin-git-manager/client-v2:"+n),o.src=e),f[e]=[t];var l=function(t,n){o.onerror=o.onload=null,clearTimeout(p);var r=f[e];if(delete f[e],o.parentNode&&o.parentNode.removeChild(o),r&&r.forEach(function(e){return e(n)}),t)return t(n)},p=setTimeout(l.bind(null,void 0,{type:"timeout",target:o}),12e4);o.onerror=l.bind(null,o.onerror),o.onload=l.bind(null,o.onload),i&&document.head.appendChild(o)},s.r=function(e){"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.g.importScripts&&(g=s.g.location+"");var f,g,d=s.g.document;if(!g&&d&&(d.currentScript&&"SCRIPT"===d.currentScript.tagName.toUpperCase()&&(g=d.currentScript.src),!g)){var b=d.getElementsByTagName("script");if(b.length)for(var h=b.length-1;h>-1&&(!g||!/^http(s?):/.test(g));)g=b[h--].src}if(!g)throw Error("Automatic publicPath is not supported in this browser");s.p=g.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),a={889:0},s.f.j=function(e,t){var n=s.o(a,e)?a[e]:void 0;if(0!==n)if(n)t.push(n[2]);else{var r=new Promise(function(t,r){n=a[e]=[t,r]});t.push(n[2]=r);var o=s.p+s.u(e),i=Error();s.l(o,function(t){if(s.o(a,e)&&(0!==(n=a[e])&&(a[e]=void 0),n)){var r=t&&("load"===t.type?"missing":t.type),o=t&&t.target&&t.target.src;i.message="Loading chunk "+e+" failed.\n("+r+": "+o+")",i.name="ChunkLoadError",i.type=r,i.request=o,n[1](i)}},"chunk-"+e,e)}},u=function(e,t){var n,r,o=t[0],i=t[1],u=t[2],c=0;if(o.some(function(e){return 0!==a[e]})){for(n in i)s.o(i,n)&&(s.m[n]=i[n]);u&&u(s)}for(e&&e(t);c<o.length;c++)r=o[c],s.o(a,r)&&a[r]&&a[r][0](),a[r]=0},(c=self.webpackChunkplugin_git_manager_client_v2=self.webpackChunkplugin_git_manager_client_v2||[]).forEach(u.bind(null,0)),c.push=u.bind(null,c.push.bind(c));var v={};return!function(){var e="",t="u">typeof document?document.currentScript:null;if(t&&t.src){var n=t.src.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"");n.indexOf("/static/plugins/plugin-git-manager/dist/client-v2/")>=0&&(e=n.replace(/\/[^\/]+$/,"/"))}if(!e){var r=window.__webpack_public_path__||"";r&&("/"!==r.charAt(r.length-1)&&(r+="/"),e=r+"static/plugins/plugin-git-manager/dist/client-v2/")}if(!e){var o=window.__nocobase_modern_client_prefix__||"v",i="/"+(o=String(o).replace(/^\/+|\/+$/g,"")||"v")+"/";if(!(e=window.__nocobase_public_path__||"")&&window.location&&window.location.pathname){var a=window.location.pathname||"/",u=a.indexOf(i);e=u>=0?a.slice(0,u+1):"/"}e&&(e=e.replace(RegExp("/"+o+"/?$"),"/")),e||(e="/"),"/"!==e.charAt(e.length-1)&&(e+="/"),e+="static/plugins/plugin-git-manager/dist/client-v2/"}s.p=e}(),!function(){s.r(v),s.d(v,{default:function(){return u}});var e=s(485);function t(e,t,n,r,o,i,a){try{var u=e[i](a),c=u.value}catch(e){n(e);return}u.done?t(c):Promise.resolve(c).then(r,o)}function n(e,t,r){return(n=a()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&o(i,n.prototype),i}).apply(null,arguments)}function r(e){return(r=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function o(e,t){return(o=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function i(e){var t="function"==typeof Map?new Map:void 0;return(i=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,i)}function i(){return n(e,arguments,r(this).constructor)}return i.prototype=Object.create(e.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),o(i,e)})(e)}function a(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(a=function(){return!!e})()}var u=function(e){var n;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function i(){var e,t;if(!(this instanceof i))throw TypeError("Cannot call a class as a function");return e=i,t=arguments,e=r(e),function(e,t){var n;if(t&&("object"==((n=t)&&"u">typeof Symbol&&n.constructor===Symbol?"symbol":typeof n)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,a()?Reflect.construct(e,t||[],r(this).constructor):e.apply(this,t))}return i.prototype=Object.create(e&&e.prototype,{constructor:{value:i,writable:!0,configurable:!0}}),e&&o(i,e),n=[{key:"load",value:function(){var e;return(e=function(){return function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),u=Object.defineProperty;return u(a,"next",{value:c(0)}),u(a,"throw",{value:c(1)}),u(a,"return",{value:c(2)}),"function"==typeof Symbol&&u(a,Symbol.iterator,{value:function(){return this}}),a;function c(u){return function(c){var l=[u,c];if(n)throw TypeError("Generator is already executing.");for(;a&&(a=0,l[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&l[0]?r.return:l[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,l[1])).done)return o;switch(r=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return i.label++,{value:l[1],done:!1};case 5:i.label++,r=l[1],l=[0];continue;case 7:l=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===l[0]||2===l[0])){i=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){i.label=l[1];break}if(6===l[0]&&i.label<o[1]){i.label=o[1],o=l;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(l);break}o[2]&&i.ops.pop(),i.trys.pop();continue}l=t.call(e,i)}catch(e){l=[6,e],r=0}finally{n=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}}(this,function(e){return this.pluginSettingsManager.addMenuItem({key:"git-manager",title:this.t("Git Manager"),icon:"BranchesOutlined"}),this.pluginSettingsManager.addPageTabItem({menuKey:"git-manager",key:"subtree-splits",title:this.t("Subtree Splits"),aclSnippet:"pm.plugin-git-manager.write",componentLoader:function(){return s.e("356").then(s.bind(s,935))}}),this.pluginSettingsManager.addPageTabItem({menuKey:"git-manager",key:"repositories",title:this.t("Repositories"),aclSnippet:"pm.plugin-git-manager.repositories",componentLoader:function(){return s.e("434").then(s.bind(s,33)).then(function(e){return{default:e.RepositoryConfig}})}}),this.pluginSettingsManager.addPageTabItem({menuKey:"git-manager",key:"manage",title:this.t("Manage"),aclSnippet:"pm.plugin-git-manager.manage",componentLoader:function(){return Promise.all([s.e("326"),s.e("900")]).then(s.bind(s,591)).then(function(e){return{default:e.GitManagerSettings}})}}),[2]})},function(){var n=this,r=arguments;return new Promise(function(o,i){var a=e.apply(n,r);function u(e){t(a,o,i,u,c,"next",e)}function c(e){t(a,o,i,u,c,"throw",e)}u(void 0)})}).call(this)}}],function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(i.prototype,n),i}(i(e.Plugin))}(),v}()});
|
|
@@ -26,12 +26,93 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
26
26
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
27
|
var role_permissions_exports = {};
|
|
28
28
|
__export(role_permissions_exports, {
|
|
29
|
+
GIT_READ_ACTIONS: () => GIT_READ_ACTIONS,
|
|
30
|
+
GIT_WRITE_ACTIONS: () => GIT_WRITE_ACTIONS,
|
|
31
|
+
REPOSITORY_READ_ACTIONS: () => REPOSITORY_READ_ACTIONS,
|
|
32
|
+
getRepositoryPermissionIds: () => getRepositoryPermissionIds,
|
|
29
33
|
rolePermissions: () => rolePermissions,
|
|
34
|
+
syncScopedActions: () => syncScopedActions,
|
|
30
35
|
updateRolePermissions: () => updateRolePermissions
|
|
31
36
|
});
|
|
32
37
|
module.exports = __toCommonJS(role_permissions_exports);
|
|
33
38
|
function getRecordValue(record, key) {
|
|
34
|
-
|
|
39
|
+
if (!record || typeof record !== "object") return void 0;
|
|
40
|
+
const model = record;
|
|
41
|
+
return typeof model.get === "function" ? model.get(key) : model[key];
|
|
42
|
+
}
|
|
43
|
+
const REPOSITORY_READ_ACTIONS = ["list", "get"];
|
|
44
|
+
const GIT_READ_ACTIONS = [
|
|
45
|
+
"status",
|
|
46
|
+
"log",
|
|
47
|
+
"branches",
|
|
48
|
+
"diff",
|
|
49
|
+
"fileTree",
|
|
50
|
+
"fileContent",
|
|
51
|
+
"commitDetail",
|
|
52
|
+
"mergeRequests",
|
|
53
|
+
"mergeRequestDetail",
|
|
54
|
+
"mergeRequestNotes",
|
|
55
|
+
"pollerStatus",
|
|
56
|
+
"subtreePreview",
|
|
57
|
+
"subtreeOptions"
|
|
58
|
+
];
|
|
59
|
+
const GIT_WRITE_ACTIONS = [
|
|
60
|
+
"clone",
|
|
61
|
+
"pull",
|
|
62
|
+
"push",
|
|
63
|
+
"fetch",
|
|
64
|
+
"checkout",
|
|
65
|
+
"triggerReview",
|
|
66
|
+
"reviewApprovePost",
|
|
67
|
+
"reviewReject",
|
|
68
|
+
"pollNow",
|
|
69
|
+
"subtreeRun"
|
|
70
|
+
];
|
|
71
|
+
function getRepositoryPermissionIds(actions, names) {
|
|
72
|
+
var _a, _b, _c;
|
|
73
|
+
const ids = /* @__PURE__ */ new Set();
|
|
74
|
+
for (const action of actions) {
|
|
75
|
+
const actionData = action.toJSON();
|
|
76
|
+
if (typeof actionData.name !== "string" || !names.includes(actionData.name)) continue;
|
|
77
|
+
const scopeRow = actionData.scope;
|
|
78
|
+
const scope = (scopeRow == null ? void 0 : scopeRow.scope) || scopeRow;
|
|
79
|
+
const scopedIds = (_c = (_b = (_a = scope == null ? void 0 : scope.$and) == null ? void 0 : _a[0]) == null ? void 0 : _b.id) == null ? void 0 : _c.$in;
|
|
80
|
+
if (Array.isArray(scopedIds)) scopedIds.forEach((id) => ids.add(id));
|
|
81
|
+
}
|
|
82
|
+
return [...ids];
|
|
83
|
+
}
|
|
84
|
+
async function syncScopedActions(db, resource, actionNames, ids) {
|
|
85
|
+
const rolesResourceId = getRecordValue(resource, "id");
|
|
86
|
+
const actionsRepo = db.getRepository("rolesResourcesActions");
|
|
87
|
+
for (const storedActionName of actionNames) {
|
|
88
|
+
const action = await actionsRepo.findOne({
|
|
89
|
+
filter: { rolesResourceId, name: storedActionName },
|
|
90
|
+
appends: ["scope"]
|
|
91
|
+
});
|
|
92
|
+
if (ids.length === 0) {
|
|
93
|
+
if (action) await action.destroy();
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const scopeJson = { $and: [{ id: { $in: ids } }] };
|
|
97
|
+
if (action) {
|
|
98
|
+
const actionData = action.toJSON();
|
|
99
|
+
const actionScopeId = getRecordValue(actionData.scope, "id") || actionData.scopeId || getRecordValue(action, "scopeId");
|
|
100
|
+
if (actionScopeId) {
|
|
101
|
+
await db.getRepository("rolesResourcesScopes").update({
|
|
102
|
+
filterByTk: actionScopeId,
|
|
103
|
+
values: { scope: scopeJson }
|
|
104
|
+
});
|
|
105
|
+
} else {
|
|
106
|
+
const newScope = await db.getRepository("rolesResourcesScopes").create({ values: { scope: scopeJson } });
|
|
107
|
+
await action.update({ scopeId: getRecordValue(newScope, "id") });
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
const newScope = await db.getRepository("rolesResourcesScopes").create({ values: { scope: scopeJson } });
|
|
111
|
+
await actionsRepo.create({
|
|
112
|
+
values: { rolesResourceId, name: storedActionName, scopeId: getRecordValue(newScope, "id") }
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
35
116
|
}
|
|
36
117
|
async function rolePermissions(ctx, _next) {
|
|
37
118
|
var _a;
|
|
@@ -53,25 +134,22 @@ async function rolePermissions(ctx, _next) {
|
|
|
53
134
|
filter: { rolesResourceId: getRecordValue(resource, "id") },
|
|
54
135
|
appends: ["scope"]
|
|
55
136
|
});
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
137
|
+
const gitManagerResource = await ctx.db.getRepository("rolesResources").findOne({
|
|
138
|
+
filter: { roleName, name: "gitManager" }
|
|
139
|
+
});
|
|
140
|
+
const gitManagerActions = gitManagerResource ? await ctx.db.getRepository("rolesResourcesActions").find({
|
|
141
|
+
filter: { rolesResourceId: getRecordValue(gitManagerResource, "id") },
|
|
142
|
+
appends: ["scope"]
|
|
143
|
+
}) : [];
|
|
144
|
+
const result = {
|
|
145
|
+
read: getRepositoryPermissionIds(actions, [...REPOSITORY_READ_ACTIONS, "read"]),
|
|
146
|
+
write: [
|
|
147
|
+
.../* @__PURE__ */ new Set([
|
|
148
|
+
...getRepositoryPermissionIds(gitManagerActions, GIT_WRITE_ACTIONS),
|
|
149
|
+
...getRepositoryPermissionIds(actions, ["write"])
|
|
150
|
+
])
|
|
151
|
+
]
|
|
152
|
+
};
|
|
75
153
|
ctx.body = result;
|
|
76
154
|
}
|
|
77
155
|
async function updateRolePermissions(ctx, _next) {
|
|
@@ -94,45 +172,32 @@ async function updateRolePermissions(ctx, _next) {
|
|
|
94
172
|
} else if (!getRecordValue(resource, "usingActionsConfig")) {
|
|
95
173
|
await resource.update({ usingActionsConfig: true });
|
|
96
174
|
}
|
|
97
|
-
const rolesResourceId = getRecordValue(resource, "id");
|
|
98
175
|
const actionsRepo = ctx.db.getRepository("rolesResourcesActions");
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
176
|
+
const readIds = permissions.read || [];
|
|
177
|
+
const writeIds = permissions.write || [];
|
|
178
|
+
const effectiveReadIds = [.../* @__PURE__ */ new Set([...readIds, ...writeIds])];
|
|
179
|
+
await syncScopedActions(ctx.db, resource, REPOSITORY_READ_ACTIONS, effectiveReadIds);
|
|
180
|
+
let gitManagerResource = await resourceRepo.findOne({ filter: { roleName, name: "gitManager" } });
|
|
181
|
+
if (!gitManagerResource) {
|
|
182
|
+
gitManagerResource = await resourceRepo.create({
|
|
183
|
+
values: { roleName, name: "gitManager", usingActionsConfig: true }
|
|
104
184
|
});
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
} else {
|
|
108
|
-
const scopeJson = { $and: [{ id: { $in: ids } }] };
|
|
109
|
-
if (action) {
|
|
110
|
-
const actionData = action.toJSON ? action.toJSON() : action;
|
|
111
|
-
const actionScope = actionData.scope;
|
|
112
|
-
const actionScopeId = getRecordValue(actionScope, "id") || actionData.scopeId || getRecordValue(action, "scopeId");
|
|
113
|
-
if (actionScopeId) {
|
|
114
|
-
await ctx.db.getRepository("rolesResourcesScopes").update({
|
|
115
|
-
filterByTk: actionScopeId,
|
|
116
|
-
values: { scope: scopeJson }
|
|
117
|
-
});
|
|
118
|
-
} else {
|
|
119
|
-
const newScope = await ctx.db.getRepository("rolesResourcesScopes").create({
|
|
120
|
-
values: { scope: scopeJson }
|
|
121
|
-
});
|
|
122
|
-
await action.update({ scopeId: getRecordValue(newScope, "id") });
|
|
123
|
-
}
|
|
124
|
-
} else {
|
|
125
|
-
const newScope = await ctx.db.getRepository("rolesResourcesScopes").create({
|
|
126
|
-
values: { scope: scopeJson }
|
|
127
|
-
});
|
|
128
|
-
await actionsRepo.create({
|
|
129
|
-
values: { rolesResourceId, name: actionName, scopeId: getRecordValue(newScope, "id") }
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
}
|
|
185
|
+
} else if (!getRecordValue(gitManagerResource, "usingActionsConfig")) {
|
|
186
|
+
await gitManagerResource.update({ usingActionsConfig: true });
|
|
133
187
|
}
|
|
188
|
+
await syncScopedActions(ctx.db, gitManagerResource, GIT_READ_ACTIONS, effectiveReadIds);
|
|
189
|
+
await syncScopedActions(ctx.db, gitManagerResource, GIT_WRITE_ACTIONS, writeIds);
|
|
190
|
+
const legacyReadAction = await actionsRepo.findOne({
|
|
191
|
+
filter: { rolesResourceId: getRecordValue(resource, "id"), name: "read" }
|
|
192
|
+
});
|
|
193
|
+
if (legacyReadAction) await legacyReadAction.destroy();
|
|
194
|
+
const legacyWriteAction = await actionsRepo.findOne({
|
|
195
|
+
filter: { rolesResourceId: getRecordValue(resource, "id"), name: "write" }
|
|
196
|
+
});
|
|
197
|
+
if (legacyWriteAction) await legacyWriteAction.destroy();
|
|
134
198
|
try {
|
|
135
199
|
await resource.writeToACL({ acl: ctx.app.acl });
|
|
200
|
+
await gitManagerResource.writeToACL({ acl: ctx.app.acl });
|
|
136
201
|
} catch (e) {
|
|
137
202
|
(_c = (_b = ctx.logger) == null ? void 0 : _b.warn) == null ? void 0 : _c.call(_b, "[git-manager] Failed to write resource to ACL memory cache:", e);
|
|
138
203
|
}
|
|
@@ -140,6 +205,11 @@ async function updateRolePermissions(ctx, _next) {
|
|
|
140
205
|
}
|
|
141
206
|
// Annotate the CommonJS export names for ESM import in node:
|
|
142
207
|
0 && (module.exports = {
|
|
208
|
+
GIT_READ_ACTIONS,
|
|
209
|
+
GIT_WRITE_ACTIONS,
|
|
210
|
+
REPOSITORY_READ_ACTIONS,
|
|
211
|
+
getRepositoryPermissionIds,
|
|
143
212
|
rolePermissions,
|
|
213
|
+
syncScopedActions,
|
|
144
214
|
updateRolePermissions
|
|
145
215
|
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var migrate_legacy_repository_permissions_exports = {};
|
|
28
|
+
__export(migrate_legacy_repository_permissions_exports, {
|
|
29
|
+
default: () => MigrateLegacyRepositoryPermissions
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(migrate_legacy_repository_permissions_exports);
|
|
32
|
+
var import_server = require("@nocobase/server");
|
|
33
|
+
var import_role_permissions = require("../actions/role-permissions");
|
|
34
|
+
function getRecordValue(record, key) {
|
|
35
|
+
if (!record || typeof record !== "object") return void 0;
|
|
36
|
+
const model = record;
|
|
37
|
+
return typeof model.get === "function" ? model.get(key) : model[key];
|
|
38
|
+
}
|
|
39
|
+
class MigrateLegacyRepositoryPermissions extends import_server.Migration {
|
|
40
|
+
on = "afterLoad";
|
|
41
|
+
async up() {
|
|
42
|
+
const resourceRepo = this.db.getRepository("rolesResources");
|
|
43
|
+
const actionsRepo = this.db.getRepository("rolesResourcesActions");
|
|
44
|
+
const repositoryResources = await resourceRepo.find({ filter: { name: "gitRepositories" } });
|
|
45
|
+
for (const repositoryResource of repositoryResources) {
|
|
46
|
+
const rolesResourceId = getRecordValue(repositoryResource, "id");
|
|
47
|
+
const roleName = getRecordValue(repositoryResource, "roleName");
|
|
48
|
+
if (!rolesResourceId || !roleName) continue;
|
|
49
|
+
const actions = await actionsRepo.find({
|
|
50
|
+
filter: { rolesResourceId },
|
|
51
|
+
appends: ["scope"]
|
|
52
|
+
});
|
|
53
|
+
const legacyRead = actions.filter((action) => getRecordValue(action, "name") === "read");
|
|
54
|
+
const legacyWrite = actions.filter((action) => getRecordValue(action, "name") === "write");
|
|
55
|
+
if (legacyRead.length === 0 && legacyWrite.length === 0) continue;
|
|
56
|
+
const readIds = (0, import_role_permissions.getRepositoryPermissionIds)(legacyRead, ["read"]);
|
|
57
|
+
const writeIds = (0, import_role_permissions.getRepositoryPermissionIds)(legacyWrite, ["write"]);
|
|
58
|
+
const effectiveReadIds = [.../* @__PURE__ */ new Set([...readIds, ...writeIds])];
|
|
59
|
+
if (effectiveReadIds.length === 0 && writeIds.length === 0) continue;
|
|
60
|
+
await (0, import_role_permissions.syncScopedActions)(this.db, repositoryResource, import_role_permissions.REPOSITORY_READ_ACTIONS, effectiveReadIds);
|
|
61
|
+
let gitManagerResource = await resourceRepo.findOne({ filter: { roleName, name: "gitManager" } });
|
|
62
|
+
if (!gitManagerResource) {
|
|
63
|
+
gitManagerResource = await resourceRepo.create({
|
|
64
|
+
values: { roleName, name: "gitManager", usingActionsConfig: true }
|
|
65
|
+
});
|
|
66
|
+
} else if (!getRecordValue(gitManagerResource, "usingActionsConfig")) {
|
|
67
|
+
await gitManagerResource.update({ usingActionsConfig: true });
|
|
68
|
+
}
|
|
69
|
+
await (0, import_role_permissions.syncScopedActions)(this.db, gitManagerResource, import_role_permissions.GIT_READ_ACTIONS, effectiveReadIds);
|
|
70
|
+
await (0, import_role_permissions.syncScopedActions)(this.db, gitManagerResource, import_role_permissions.GIT_WRITE_ACTIONS, writeIds);
|
|
71
|
+
for (const action of [...legacyRead, ...legacyWrite]) {
|
|
72
|
+
await action.destroy();
|
|
73
|
+
}
|
|
74
|
+
await repositoryResource.writeToACL({ acl: this.app.acl });
|
|
75
|
+
await gitManagerResource.writeToACL({ acl: this.app.acl });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
package/dist/server/plugin.js
CHANGED
|
@@ -54,6 +54,7 @@ var import_review = require("./actions/review");
|
|
|
54
54
|
var import_ai_tools = require("./ai-tools");
|
|
55
55
|
var import_poller = require("./poller");
|
|
56
56
|
var import_registry_content_service = require("./services/registry-content-service");
|
|
57
|
+
var import_repository_access = require("./repository-access");
|
|
57
58
|
class PluginGitManagerServer extends import_server.Plugin {
|
|
58
59
|
registryContentService;
|
|
59
60
|
async afterAdd() {
|
|
@@ -106,6 +107,7 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
106
107
|
subtreeReplace: subtreeActions.subtreeRunOnAppProcess
|
|
107
108
|
}
|
|
108
109
|
});
|
|
110
|
+
this.app.resourceManager.use(import_repository_access.enforceRepositoryAccess);
|
|
109
111
|
this.app.use(async (ctx, next) => {
|
|
110
112
|
if (ctx.logger && ctx.logger.warn) {
|
|
111
113
|
const originalWarn = ctx.logger.warn.bind(ctx.logger);
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var repository_access_exports = {};
|
|
28
|
+
__export(repository_access_exports, {
|
|
29
|
+
enforceRepositoryAccess: () => enforceRepositoryAccess
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(repository_access_exports);
|
|
32
|
+
const REPOSITORY_SCOPED_ACTIONS = /* @__PURE__ */ new Set([
|
|
33
|
+
"clone",
|
|
34
|
+
"pull",
|
|
35
|
+
"push",
|
|
36
|
+
"fetch",
|
|
37
|
+
"diff",
|
|
38
|
+
"status",
|
|
39
|
+
"log",
|
|
40
|
+
"branches",
|
|
41
|
+
"checkout",
|
|
42
|
+
"fileTree",
|
|
43
|
+
"fileContent",
|
|
44
|
+
"commitDetail",
|
|
45
|
+
"mergeRequests",
|
|
46
|
+
"mergeRequestDetail",
|
|
47
|
+
"mergeRequestNotes",
|
|
48
|
+
"triggerReview",
|
|
49
|
+
"pollNow",
|
|
50
|
+
"subtreePreview",
|
|
51
|
+
"subtreeOptions"
|
|
52
|
+
]);
|
|
53
|
+
function scopeIncludesRepository(filter, repositoryId) {
|
|
54
|
+
if (!filter || typeof filter !== "object") return true;
|
|
55
|
+
const scope = filter;
|
|
56
|
+
if (Object.keys(scope).length === 0) return true;
|
|
57
|
+
if (Array.isArray(scope.$and)) {
|
|
58
|
+
return scope.$and.every((condition) => scopeIncludesRepository(condition, repositoryId));
|
|
59
|
+
}
|
|
60
|
+
if (Array.isArray(scope.$or)) {
|
|
61
|
+
return scope.$or.some((condition) => scopeIncludesRepository(condition, repositoryId));
|
|
62
|
+
}
|
|
63
|
+
const id = scope.id;
|
|
64
|
+
if (id && typeof id === "object") {
|
|
65
|
+
const allowedIds = id.$in;
|
|
66
|
+
return Array.isArray(allowedIds) && allowedIds.some((allowedId) => String(allowedId) === String(repositoryId));
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
async function enforceRepositoryAccess(ctx, next) {
|
|
71
|
+
var _a, _b, _c, _d, _e;
|
|
72
|
+
if (((_a = ctx.action) == null ? void 0 : _a.resourceName) !== "gitManager" || !REPOSITORY_SCOPED_ACTIONS.has((_b = ctx.action) == null ? void 0 : _b.actionName)) {
|
|
73
|
+
return next();
|
|
74
|
+
}
|
|
75
|
+
const repositoryId = (_c = ctx.action.params) == null ? void 0 : _c.repositoryId;
|
|
76
|
+
if (repositoryId == null) return next();
|
|
77
|
+
const roles = Array.isArray((_d = ctx.state) == null ? void 0 : _d.currentRoles) ? ctx.state.currentRoles : [];
|
|
78
|
+
if (roles.includes("root")) return next();
|
|
79
|
+
const permission = await ctx.app.acl.can({
|
|
80
|
+
roles,
|
|
81
|
+
resource: "gitManager",
|
|
82
|
+
action: ctx.action.actionName
|
|
83
|
+
});
|
|
84
|
+
if (!permission || !scopeIncludesRepository((_e = permission.params) == null ? void 0 : _e.filter, repositoryId)) {
|
|
85
|
+
return ctx.throw(403, "Permission denied");
|
|
86
|
+
}
|
|
87
|
+
return next();
|
|
88
|
+
}
|
|
89
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
90
|
+
0 && (module.exports = {
|
|
91
|
+
enforceRepositoryAccess
|
|
92
|
+
});
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"displayName": "Git Manager",
|
|
4
4
|
"displayName.zh-CN": "Git 管理器",
|
|
5
5
|
"description": "Manage Git repositories with PAT authentication - pull, push, fetch, diff, file browsing",
|
|
6
|
-
"version": "1.2.
|
|
6
|
+
"version": "1.2.23",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"main": "dist/server/index.js",
|
|
9
9
|
"files": [
|
|
@@ -279,7 +279,7 @@ export const RepositoryConfig: React.FC = () => {
|
|
|
279
279
|
}}
|
|
280
280
|
width={520}
|
|
281
281
|
>
|
|
282
|
-
<Form form={form} layout="vertical" initialValues={{ defaultBranch: 'main' }}>
|
|
282
|
+
<Form form={form} layout="vertical" initialValues={{ defaultBranch: 'main', registryExportEnabled: false }}>
|
|
283
283
|
<Form.Item name="name" label={t('Repository Name')} rules={[{ required: true }]}>
|
|
284
284
|
<Input placeholder="my-project" />
|
|
285
285
|
</Form.Item>
|
|
@@ -307,6 +307,9 @@ export const RepositoryConfig: React.FC = () => {
|
|
|
307
307
|
<Form.Item name="defaultBranch" label={t('Default Branch')}>
|
|
308
308
|
<Input placeholder="main" />
|
|
309
309
|
</Form.Item>
|
|
310
|
+
<Form.Item name="registryExportEnabled" label={t('Allow Skill Registry export')} valuePropName="checked">
|
|
311
|
+
<Switch />
|
|
312
|
+
</Form.Item>
|
|
310
313
|
<Form.Item
|
|
311
314
|
name="autoReviewFlowId"
|
|
312
315
|
label={t('Primary Auto Review Flow')}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { enforceRepositoryAccess } from '../repository-access';
|
|
2
|
+
import { vi } from 'vitest';
|
|
3
|
+
|
|
4
|
+
function createContext(repositoryId: number, filter?: unknown, roles = ['developer']) {
|
|
5
|
+
const throwError = vi.fn((status: number, message: string) => {
|
|
6
|
+
const error = new Error(message) as Error & { status: number };
|
|
7
|
+
error.status = status;
|
|
8
|
+
throw error;
|
|
9
|
+
});
|
|
10
|
+
return {
|
|
11
|
+
action: { resourceName: 'gitManager', actionName: 'fileTree', params: { repositoryId } },
|
|
12
|
+
state: { currentRoles: roles },
|
|
13
|
+
app: {
|
|
14
|
+
acl: {
|
|
15
|
+
can: vi.fn().mockResolvedValue({ params: filter === undefined ? {} : { filter } }),
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
throw: throwError,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe('Git Manager repository access', () => {
|
|
23
|
+
it('allows the repository included in the role scope', async () => {
|
|
24
|
+
const ctx = createContext(10, { $and: [{ id: { $in: [10] } }] });
|
|
25
|
+
const next = vi.fn().mockResolvedValue(undefined);
|
|
26
|
+
|
|
27
|
+
await enforceRepositoryAccess(ctx, next);
|
|
28
|
+
|
|
29
|
+
expect(next).toHaveBeenCalledTimes(1);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('rejects another repository outside the role scope', async () => {
|
|
33
|
+
const ctx = createContext(20, { $and: [{ id: { $in: [10] } }] });
|
|
34
|
+
|
|
35
|
+
await expect(enforceRepositoryAccess(ctx, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('accepts a repository granted by one of multiple roles', async () => {
|
|
39
|
+
const ctx = createContext(20, {
|
|
40
|
+
$or: [{ $and: [{ id: { $in: [10] } }] }, { $and: [{ id: { $in: [20] } }] }],
|
|
41
|
+
});
|
|
42
|
+
const next = vi.fn().mockResolvedValue(undefined);
|
|
43
|
+
|
|
44
|
+
await enforceRepositoryAccess(ctx, next);
|
|
45
|
+
|
|
46
|
+
expect(next).toHaveBeenCalledTimes(1);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('allows root without evaluating repository scope', async () => {
|
|
50
|
+
const ctx = createContext(20, { $and: [{ id: { $in: [10] } }] }, ['root']);
|
|
51
|
+
const next = vi.fn().mockResolvedValue(undefined);
|
|
52
|
+
|
|
53
|
+
await enforceRepositoryAccess(ctx, next);
|
|
54
|
+
|
|
55
|
+
expect(next).toHaveBeenCalledTimes(1);
|
|
56
|
+
expect(ctx.app.acl.can).not.toHaveBeenCalled();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Model } from '@nocobase/database';
|
|
2
|
+
|
|
3
|
+
import { getRepositoryPermissionIds } from '../actions/role-permissions';
|
|
4
|
+
|
|
5
|
+
function permissionAction(name: string, repositoryIds: Array<number | string>) {
|
|
6
|
+
return {
|
|
7
|
+
toJSON: () => ({
|
|
8
|
+
name,
|
|
9
|
+
scope: { scope: { $and: [{ id: { $in: repositoryIds } }] } },
|
|
10
|
+
}),
|
|
11
|
+
} as unknown as Model;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
describe('Git Manager role permissions', () => {
|
|
15
|
+
it('reads repository IDs from legacy scoped actions', () => {
|
|
16
|
+
const actions = [permissionAction('read', [1]), permissionAction('write', [1, 2])];
|
|
17
|
+
|
|
18
|
+
expect(getRepositoryPermissionIds(actions, ['read', 'write'])).toEqual([1, 2]);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('does not include repository IDs from unrelated actions', () => {
|
|
22
|
+
const actions = [permissionAction('destroy', [3]), permissionAction('write', [1])];
|
|
23
|
+
|
|
24
|
+
expect(getRepositoryPermissionIds(actions, ['write'])).toEqual([1]);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -1,5 +1,91 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { Database, Model } from '@nocobase/database';
|
|
2
|
+
|
|
3
|
+
function getRecordValue(record: unknown, key: string) {
|
|
4
|
+
if (!record || typeof record !== 'object') return undefined;
|
|
5
|
+
const model = record as { get?: (attribute: string) => unknown } & Record<string, unknown>;
|
|
6
|
+
return typeof model.get === 'function' ? model.get(key) : model[key];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const REPOSITORY_READ_ACTIONS = ['list', 'get'] as const;
|
|
10
|
+
export const GIT_READ_ACTIONS = [
|
|
11
|
+
'status',
|
|
12
|
+
'log',
|
|
13
|
+
'branches',
|
|
14
|
+
'diff',
|
|
15
|
+
'fileTree',
|
|
16
|
+
'fileContent',
|
|
17
|
+
'commitDetail',
|
|
18
|
+
'mergeRequests',
|
|
19
|
+
'mergeRequestDetail',
|
|
20
|
+
'mergeRequestNotes',
|
|
21
|
+
'pollerStatus',
|
|
22
|
+
'subtreePreview',
|
|
23
|
+
'subtreeOptions',
|
|
24
|
+
] as const;
|
|
25
|
+
export const GIT_WRITE_ACTIONS = [
|
|
26
|
+
'clone',
|
|
27
|
+
'pull',
|
|
28
|
+
'push',
|
|
29
|
+
'fetch',
|
|
30
|
+
'checkout',
|
|
31
|
+
'triggerReview',
|
|
32
|
+
'reviewApprovePost',
|
|
33
|
+
'reviewReject',
|
|
34
|
+
'pollNow',
|
|
35
|
+
'subtreeRun',
|
|
36
|
+
] as const;
|
|
37
|
+
|
|
38
|
+
export function getRepositoryPermissionIds(actions: Model[], names: readonly string[]) {
|
|
39
|
+
const ids = new Set<number | string>();
|
|
40
|
+
for (const action of actions) {
|
|
41
|
+
const actionData = action.toJSON() as Record<string, unknown>;
|
|
42
|
+
if (typeof actionData.name !== 'string' || !names.includes(actionData.name)) continue;
|
|
43
|
+
const scopeRow = actionData.scope as { scope?: unknown } | undefined;
|
|
44
|
+
const scope = scopeRow?.scope || scopeRow;
|
|
45
|
+
const scopedIds = (scope as { $and?: Array<{ id?: { $in?: unknown } }> } | undefined)?.$and?.[0]?.id?.$in;
|
|
46
|
+
if (Array.isArray(scopedIds)) scopedIds.forEach((id: number | string) => ids.add(id));
|
|
47
|
+
}
|
|
48
|
+
return [...ids];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function syncScopedActions(
|
|
52
|
+
db: Database,
|
|
53
|
+
resource: Model,
|
|
54
|
+
actionNames: readonly string[],
|
|
55
|
+
ids: Array<number | string>,
|
|
56
|
+
) {
|
|
57
|
+
const rolesResourceId = getRecordValue(resource, 'id');
|
|
58
|
+
const actionsRepo = db.getRepository('rolesResourcesActions');
|
|
59
|
+
for (const storedActionName of actionNames) {
|
|
60
|
+
const action = await actionsRepo.findOne({
|
|
61
|
+
filter: { rolesResourceId, name: storedActionName },
|
|
62
|
+
appends: ['scope'],
|
|
63
|
+
});
|
|
64
|
+
if (ids.length === 0) {
|
|
65
|
+
if (action) await action.destroy();
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const scopeJson = { $and: [{ id: { $in: ids } }] };
|
|
69
|
+
if (action) {
|
|
70
|
+
const actionData = action.toJSON() as Record<string, unknown>;
|
|
71
|
+
const actionScopeId =
|
|
72
|
+
getRecordValue(actionData.scope, 'id') || actionData.scopeId || getRecordValue(action, 'scopeId');
|
|
73
|
+
if (actionScopeId) {
|
|
74
|
+
await db.getRepository('rolesResourcesScopes').update({
|
|
75
|
+
filterByTk: actionScopeId,
|
|
76
|
+
values: { scope: scopeJson },
|
|
77
|
+
});
|
|
78
|
+
} else {
|
|
79
|
+
const newScope = await db.getRepository('rolesResourcesScopes').create({ values: { scope: scopeJson } });
|
|
80
|
+
await action.update({ scopeId: getRecordValue(newScope, 'id') });
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
const newScope = await db.getRepository('rolesResourcesScopes').create({ values: { scope: scopeJson } });
|
|
84
|
+
await actionsRepo.create({
|
|
85
|
+
values: { rolesResourceId, name: storedActionName, scopeId: getRecordValue(newScope, 'id') },
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
3
89
|
}
|
|
4
90
|
|
|
5
91
|
/**
|
|
@@ -27,27 +113,25 @@ export async function rolePermissions(ctx: any, _next: () => Promise<void>) {
|
|
|
27
113
|
filter: { rolesResourceId: getRecordValue(resource, 'id') },
|
|
28
114
|
appends: ['scope'],
|
|
29
115
|
});
|
|
116
|
+
const gitManagerResource = await ctx.db.getRepository('rolesResources').findOne({
|
|
117
|
+
filter: { roleName, name: 'gitManager' },
|
|
118
|
+
});
|
|
119
|
+
const gitManagerActions = gitManagerResource
|
|
120
|
+
? await ctx.db.getRepository('rolesResourcesActions').find({
|
|
121
|
+
filter: { rolesResourceId: getRecordValue(gitManagerResource, 'id') },
|
|
122
|
+
appends: ['scope'],
|
|
123
|
+
})
|
|
124
|
+
: [];
|
|
30
125
|
|
|
31
|
-
const result = {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (scope.$and[0].id.$in) {
|
|
41
|
-
result[actionName] = scope.$and[0].id.$in;
|
|
42
|
-
} else if (typeof scope.$and[0].id === 'number' || typeof scope.$and[0].id === 'string') {
|
|
43
|
-
result[actionName] = [scope.$and[0].id];
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
} catch (e) {
|
|
47
|
-
// Unrecognized scope structure, skip
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
126
|
+
const result = {
|
|
127
|
+
read: getRepositoryPermissionIds(actions, [...REPOSITORY_READ_ACTIONS, 'read']),
|
|
128
|
+
write: [
|
|
129
|
+
...new Set([
|
|
130
|
+
...getRepositoryPermissionIds(gitManagerActions, GIT_WRITE_ACTIONS),
|
|
131
|
+
...getRepositoryPermissionIds(actions, ['write']),
|
|
132
|
+
]),
|
|
133
|
+
],
|
|
134
|
+
};
|
|
51
135
|
ctx.body = result;
|
|
52
136
|
}
|
|
53
137
|
|
|
@@ -77,50 +161,36 @@ export async function updateRolePermissions(ctx: any, _next: () => Promise<void>
|
|
|
77
161
|
await resource.update({ usingActionsConfig: true });
|
|
78
162
|
}
|
|
79
163
|
|
|
80
|
-
const rolesResourceId = getRecordValue(resource, 'id');
|
|
81
164
|
const actionsRepo = ctx.db.getRepository('rolesResourcesActions');
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
appends: ['scope'],
|
|
87
|
-
});
|
|
165
|
+
const readIds = permissions.read || [];
|
|
166
|
+
const writeIds = permissions.write || [];
|
|
167
|
+
const effectiveReadIds = [...new Set([...readIds, ...writeIds])];
|
|
168
|
+
await syncScopedActions(ctx.db, resource, REPOSITORY_READ_ACTIONS, effectiveReadIds);
|
|
88
169
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const actionScope = actionData.scope;
|
|
97
|
-
const actionScopeId =
|
|
98
|
-
getRecordValue(actionScope, 'id') || actionData.scopeId || getRecordValue(action, 'scopeId');
|
|
99
|
-
if (actionScopeId) {
|
|
100
|
-
await ctx.db.getRepository('rolesResourcesScopes').update({
|
|
101
|
-
filterByTk: actionScopeId,
|
|
102
|
-
values: { scope: scopeJson },
|
|
103
|
-
});
|
|
104
|
-
} else {
|
|
105
|
-
const newScope = await ctx.db.getRepository('rolesResourcesScopes').create({
|
|
106
|
-
values: { scope: scopeJson },
|
|
107
|
-
});
|
|
108
|
-
await action.update({ scopeId: getRecordValue(newScope, 'id') });
|
|
109
|
-
}
|
|
110
|
-
} else {
|
|
111
|
-
const newScope = await ctx.db.getRepository('rolesResourcesScopes').create({
|
|
112
|
-
values: { scope: scopeJson },
|
|
113
|
-
});
|
|
114
|
-
await actionsRepo.create({
|
|
115
|
-
values: { rolesResourceId, name: actionName, scopeId: getRecordValue(newScope, 'id') },
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
}
|
|
170
|
+
let gitManagerResource = await resourceRepo.findOne({ filter: { roleName, name: 'gitManager' } });
|
|
171
|
+
if (!gitManagerResource) {
|
|
172
|
+
gitManagerResource = await resourceRepo.create({
|
|
173
|
+
values: { roleName, name: 'gitManager', usingActionsConfig: true },
|
|
174
|
+
});
|
|
175
|
+
} else if (!getRecordValue(gitManagerResource, 'usingActionsConfig')) {
|
|
176
|
+
await gitManagerResource.update({ usingActionsConfig: true });
|
|
119
177
|
}
|
|
178
|
+
await syncScopedActions(ctx.db, gitManagerResource, GIT_READ_ACTIONS, effectiveReadIds);
|
|
179
|
+
await syncScopedActions(ctx.db, gitManagerResource, GIT_WRITE_ACTIONS, writeIds);
|
|
180
|
+
|
|
181
|
+
const legacyReadAction = await actionsRepo.findOne({
|
|
182
|
+
filter: { rolesResourceId: getRecordValue(resource, 'id'), name: 'read' },
|
|
183
|
+
});
|
|
184
|
+
if (legacyReadAction) await legacyReadAction.destroy();
|
|
185
|
+
const legacyWriteAction = await actionsRepo.findOne({
|
|
186
|
+
filter: { rolesResourceId: getRecordValue(resource, 'id'), name: 'write' },
|
|
187
|
+
});
|
|
188
|
+
if (legacyWriteAction) await legacyWriteAction.destroy();
|
|
120
189
|
|
|
121
190
|
// Force reload the ACL cache in memory for this resource
|
|
122
191
|
try {
|
|
123
192
|
await resource.writeToACL({ acl: ctx.app.acl });
|
|
193
|
+
await gitManagerResource.writeToACL({ acl: ctx.app.acl });
|
|
124
194
|
} catch (e) {
|
|
125
195
|
ctx.logger?.warn?.('[git-manager] Failed to write resource to ACL memory cache:', e);
|
|
126
196
|
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Migration } from '@nocobase/server';
|
|
2
|
+
import type { Model } from '@nocobase/database';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
GIT_READ_ACTIONS,
|
|
6
|
+
GIT_WRITE_ACTIONS,
|
|
7
|
+
REPOSITORY_READ_ACTIONS,
|
|
8
|
+
getRepositoryPermissionIds,
|
|
9
|
+
syncScopedActions,
|
|
10
|
+
} from '../actions/role-permissions';
|
|
11
|
+
|
|
12
|
+
function getRecordValue(record: unknown, key: string) {
|
|
13
|
+
if (!record || typeof record !== 'object') return undefined;
|
|
14
|
+
const model = record as { get?: (attribute: string) => unknown } & Record<string, unknown>;
|
|
15
|
+
return typeof model.get === 'function' ? model.get(key) : model[key];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default class MigrateLegacyRepositoryPermissions extends Migration {
|
|
19
|
+
on = 'afterLoad';
|
|
20
|
+
|
|
21
|
+
async up() {
|
|
22
|
+
const resourceRepo = this.db.getRepository('rolesResources');
|
|
23
|
+
const actionsRepo = this.db.getRepository('rolesResourcesActions');
|
|
24
|
+
const repositoryResources = await resourceRepo.find({ filter: { name: 'gitRepositories' } });
|
|
25
|
+
|
|
26
|
+
for (const repositoryResource of repositoryResources) {
|
|
27
|
+
const rolesResourceId = getRecordValue(repositoryResource, 'id');
|
|
28
|
+
const roleName = getRecordValue(repositoryResource, 'roleName');
|
|
29
|
+
if (!rolesResourceId || !roleName) continue;
|
|
30
|
+
|
|
31
|
+
const actions = await actionsRepo.find({
|
|
32
|
+
filter: { rolesResourceId },
|
|
33
|
+
appends: ['scope'],
|
|
34
|
+
});
|
|
35
|
+
const legacyRead = actions.filter((action) => getRecordValue(action, 'name') === 'read') as Model[];
|
|
36
|
+
const legacyWrite = actions.filter((action) => getRecordValue(action, 'name') === 'write') as Model[];
|
|
37
|
+
if (legacyRead.length === 0 && legacyWrite.length === 0) continue;
|
|
38
|
+
|
|
39
|
+
const readIds = getRepositoryPermissionIds(legacyRead, ['read']);
|
|
40
|
+
const writeIds = getRepositoryPermissionIds(legacyWrite, ['write']);
|
|
41
|
+
const effectiveReadIds = [...new Set([...readIds, ...writeIds])];
|
|
42
|
+
if (effectiveReadIds.length === 0 && writeIds.length === 0) continue;
|
|
43
|
+
|
|
44
|
+
await syncScopedActions(this.db, repositoryResource, REPOSITORY_READ_ACTIONS, effectiveReadIds);
|
|
45
|
+
|
|
46
|
+
let gitManagerResource = await resourceRepo.findOne({ filter: { roleName, name: 'gitManager' } });
|
|
47
|
+
if (!gitManagerResource) {
|
|
48
|
+
gitManagerResource = await resourceRepo.create({
|
|
49
|
+
values: { roleName, name: 'gitManager', usingActionsConfig: true },
|
|
50
|
+
});
|
|
51
|
+
} else if (!getRecordValue(gitManagerResource, 'usingActionsConfig')) {
|
|
52
|
+
await gitManagerResource.update({ usingActionsConfig: true });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
await syncScopedActions(this.db, gitManagerResource, GIT_READ_ACTIONS, effectiveReadIds);
|
|
56
|
+
await syncScopedActions(this.db, gitManagerResource, GIT_WRITE_ACTIONS, writeIds);
|
|
57
|
+
|
|
58
|
+
for (const action of [...legacyRead, ...legacyWrite]) {
|
|
59
|
+
await action.destroy();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
await repositoryResource.writeToACL({ acl: this.app.acl });
|
|
63
|
+
await gitManagerResource.writeToACL({ acl: this.app.acl });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
package/src/server/plugin.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { recoverStuckReviews, registerReviewQueue, unregisterReviewQueue } from
|
|
|
12
12
|
import { registerGitReviewAiTools } from './ai-tools';
|
|
13
13
|
import { startPoller, stopPoller } from './poller';
|
|
14
14
|
import { RegistryGitContentService } from './services/registry-content-service';
|
|
15
|
+
import { enforceRepositoryAccess } from './repository-access';
|
|
15
16
|
|
|
16
17
|
export class PluginGitManagerServer extends Plugin {
|
|
17
18
|
// @ts-ignore
|
|
@@ -76,6 +77,8 @@ export class PluginGitManagerServer extends Plugin {
|
|
|
76
77
|
},
|
|
77
78
|
});
|
|
78
79
|
|
|
80
|
+
(this as any).app.resourceManager.use(enforceRepositoryAccess);
|
|
81
|
+
|
|
79
82
|
// Suppress noisy workflow pre-action/post-action warnings for custom resources
|
|
80
83
|
(this as any).app.use(async (ctx, next) => {
|
|
81
84
|
if (ctx.logger && ctx.logger.warn) {
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const REPOSITORY_SCOPED_ACTIONS = new Set([
|
|
2
|
+
'clone',
|
|
3
|
+
'pull',
|
|
4
|
+
'push',
|
|
5
|
+
'fetch',
|
|
6
|
+
'diff',
|
|
7
|
+
'status',
|
|
8
|
+
'log',
|
|
9
|
+
'branches',
|
|
10
|
+
'checkout',
|
|
11
|
+
'fileTree',
|
|
12
|
+
'fileContent',
|
|
13
|
+
'commitDetail',
|
|
14
|
+
'mergeRequests',
|
|
15
|
+
'mergeRequestDetail',
|
|
16
|
+
'mergeRequestNotes',
|
|
17
|
+
'triggerReview',
|
|
18
|
+
'pollNow',
|
|
19
|
+
'subtreePreview',
|
|
20
|
+
'subtreeOptions',
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
type PermissionResult = { params?: { filter?: unknown } } | null;
|
|
24
|
+
|
|
25
|
+
function scopeIncludesRepository(filter: unknown, repositoryId: number | string): boolean {
|
|
26
|
+
if (!filter || typeof filter !== 'object') return true;
|
|
27
|
+
const scope = filter as Record<string, unknown>;
|
|
28
|
+
if (Object.keys(scope).length === 0) return true;
|
|
29
|
+
if (Array.isArray(scope.$and)) {
|
|
30
|
+
return scope.$and.every((condition) => scopeIncludesRepository(condition, repositoryId));
|
|
31
|
+
}
|
|
32
|
+
if (Array.isArray(scope.$or)) {
|
|
33
|
+
return scope.$or.some((condition) => scopeIncludesRepository(condition, repositoryId));
|
|
34
|
+
}
|
|
35
|
+
const id = scope.id;
|
|
36
|
+
if (id && typeof id === 'object') {
|
|
37
|
+
const allowedIds = (id as { $in?: Array<number | string> }).$in;
|
|
38
|
+
return Array.isArray(allowedIds) && allowedIds.some((allowedId) => String(allowedId) === String(repositoryId));
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function enforceRepositoryAccess(ctx: any, next: () => Promise<void>) {
|
|
44
|
+
if (ctx.action?.resourceName !== 'gitManager' || !REPOSITORY_SCOPED_ACTIONS.has(ctx.action?.actionName)) {
|
|
45
|
+
return next();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const repositoryId = ctx.action.params?.repositoryId;
|
|
49
|
+
if (repositoryId == null) return next();
|
|
50
|
+
|
|
51
|
+
const roles = Array.isArray(ctx.state?.currentRoles) ? ctx.state.currentRoles : [];
|
|
52
|
+
if (roles.includes('root')) return next();
|
|
53
|
+
|
|
54
|
+
const permission = (await ctx.app.acl.can({
|
|
55
|
+
roles,
|
|
56
|
+
resource: 'gitManager',
|
|
57
|
+
action: ctx.action.actionName,
|
|
58
|
+
})) as PermissionResult;
|
|
59
|
+
if (!permission || !scopeIncludesRepository(permission.params?.filter, repositoryId)) {
|
|
60
|
+
return ctx.throw(403, 'Permission denied');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return next();
|
|
64
|
+
}
|