Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: gitlab commit #94

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package = "/plugins/@iteria-netlify-plugin"
Access-Control-Allow-Origin = "*"

[build]
command = "npx [email protected] i --store=node_modules/.pnpm-store && npx [email protected] run build"
command = "cd netlify && npx [email protected] i && cd .. && npx [email protected] i --store=node_modules/.pnpm-store && npx [email protected] run build"
publish = "dist"

functions ='netlify/functions'



24 changes: 24 additions & 0 deletions netlify/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
51 changes: 51 additions & 0 deletions netlify/functions/gitlabCommit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import fetch from 'node-fetch'

exports.handler = async (event) => {

const commitData = JSON.parse(event.body)
const actions : {action: string, content: string, file_path: string}[] = []
console.log(encodeURIComponent(commitData.projectPath))
for (const [path, file] of Object.entries(commitData.changedFiles)) {
if (file.data != null) {
if(file.newFile)
actions.push({action: "create", content: file.data, file_path: path})
else
actions.push({action: "update", content: file.data, file_path: path})
} else {
actions.push({action: "delete", content: file.data, file_path: path})
}
}

const body = {
id: encodeURIComponent(commitData.projectPath),
branch: commitData.branch,
commit_message: commitData.commitMessage,
actions: actions

}

const requestOptions = {
method: 'POST',
headers: {
"Content-Type": "application/json",
"PRIVATE-TOKEN": commitData.token,
},
body: JSON.stringify(body),
};

const res = await fetch(`https://gitlab.com/api/v4/projects/${encodeURIComponent(commitData.projectPath)}/repository/commits`, requestOptions)
const result = await res.json()
console.log(result)

if (result.errors) {
return {
statusCode: 400,
body: JSON.stringify({ success: false, errors: result.errors })
}
} else {
return {
statusCode: 200,
body: JSON.stringify({ success: true, errors: '' })
}
}
}
30 changes: 30 additions & 0 deletions netlify/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "test",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"netlify:build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"@netlify/functions": "^1.0.0",
"@swc/core": "^1.2.160",
"@types/es6-promise": "^3.3.0",
"date-fns": "^2.28.0",
"express": "^4.17.3",
"graphql": "^16.3.0",
"node-fetch": "2",
"urql": "^2.2.0"
},
"devDependencies": {
"@vitejs/plugin-react": "^1.0.7",
"netlify-cli": "4.0.3",
"typescript": "^4.5.4",
"vite": "^2.8.6",
"vite-plugin-cross-origin-isolation": "^0.1.6",
"vite-plugin-node": "^0.0.18"
}
}
Loading