Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
luminy-org
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Eloi Perdereau
luminy-org
Commits
918e0c44
Commit
918e0c44
authored
4 years ago
by
Eloi Perdereau
Browse files
Options
Downloads
Patches
Plain Diff
add test fonction lambda: commit nouveau post fb
parent
19fcb2b3
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lambda/zapierCommit.js
+80
-0
80 additions, 0 deletions
lambda/zapierCommit.js
with
80 additions
and
0 deletions
lambda/zapierCommit.js
0 → 100644
+
80
−
0
View file @
918e0c44
const
Octokit
=
require
(
'
@octokit/rest
'
),
owner
=
'
CCLuminy
'
,
repo
=
'
luminy.org
'
;
branch
=
'
content
'
exports
.
handler
=
async
(
event
,
context
,
callback
)
=>
{
try
{
const
octokit
=
new
Octokit
({
auth
:
process
.
env
.
GITHUB_TOKEN
});
if
(
!
event
.
body
)
{
return
{
statusCode
:
500
,
body
:
'
rien dans event.body
'
};
}
const
body
=
JSON
.
parse
(
event
.
body
);
const
newItem
=
{};
newItem
.
link
=
body
.
link
;
newItem
.
message
=
body
.
message
;
newItem
.
picture
=
body
.
picture
;
if
(
!
newItem
.
link
)
{
return
{
statusCode
:
500
,
body
:
'
pas de link
'
};
}
if
(
!
newItem
.
message
)
{
return
{
statusCode
:
500
,
body
:
'
pas de message
'
};
}
if
(
!
newItem
.
picture
)
{
return
{
statusCode
:
500
,
body
:
'
pas de picture
'
};
}
let
path
=
'
_pages/agenda.md
'
;
return
octokit
.
repos
.
getContents
({
owner
,
repo
,
path
,
branch
})
.
then
((
res
)
=>
{
console
.
log
(
res
);
let
buff
=
Buffer
.
from
(
res
.
data
.
content
,
'
base64
'
);
let
pageRaw
=
buff
.
toString
(
'
utf-8
'
);
// let linksJSON = JSON.parse(linksRaw);
let
message
=
'
Nouveau post facebook
'
;
let
content
=
''
;
let
sha
=
res
.
data
.
sha
;
// linksJSON.links.push(newItem);
// linksRaw = JSON.stringify(linksJSON);
buff
=
Buffer
.
from
(
pageRaw
+
newItem
.
link
+
'
\n
'
);
content
=
buff
.
toString
(
'
base64
'
);
return
octokit
.
repos
.
createOrUpdateFile
({
owner
,
repo
,
path
,
message
,
content
,
sha
,
branch
})
.
then
((
res
)
=>
{
return
{
statusCode
:
200
,
body
:
'
{"success":"true"}
'
};
});
});
}
catch
(
err
)
{
[];
return
{
statusCode
:
500
,
body
:
err
.
toString
()
};
}
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment