This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Require express and body-parser | |
const express = require("express"); | |
const bodyParser = require("body-parser"); | |
const delve = require('dlv'); | |
const axios = require('axios'); | |
const FormData = require('form-data'); | |
// Initialize express and define a port | |
const app = express(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.post("/hook", (req, res) => { | |
let payload = req.body; | |
let header = req.headers; | |
res.status(200).end() | |
let pullRequestBranch = getPullRequestBranch(payload); | |
let baseBranch = getBaseBranch(payload); | |
let commitURL = getCommitURL(payload); | |
let action = getAction(payload); | |
let XGithubDelivery = getXGithubDelivery(header); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getPullRequestBranch(payload) { | |
return pullRequestBranch = delve(payload, 'pull_request.head.ref'); | |
} | |
function getBaseBranch(payload) { | |
return baseBranch = delve(payload, 'pull_request.base.ref'); | |
} | |
function getCommitURL(payload) { | |
return commitURL = delve(payload, 'pull_request.statuses_url'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let XGithubDelivery = getXGithubDelivery(header); | |
let XGithubEvent = getXGithubEvent(header); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function updateCommitStatus(commitURL, state, jenkinsTargetUrl, message, accessToken) { | |
let data = JSON.stringify({"state":`${state}`,"target_url":`${jenkinsTargetUrl}`,"description":`${message}`,"context":"continuous-integration/jenkins"}); | |
let config = { | |
method: 'post', | |
url: `${commitURL}?access_token=${accessToken}`, | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
data : data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function postToJenkins(payload, jenkinsTargetUrl, token, basicAuth, XGithubDelivery) { | |
let data = new FormData(); | |
data.append('payload', `${JSON.stringify(payload)}`); | |
let config = { | |
method: 'post', | |
url: `${jenkinsTargetUrl}buildWithParameters?token=${token}`, | |
headers: { | |
'X-Github-Delivery': `${XGithubDelivery}`, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getXGithubDelivery(header) { | |
return commitURL = delve(header, 'x-github-delivery'); | |
} | |
function getXGithubEvent(header) { | |
return commitURL = delve(header, 'x-github-event'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const airtable = require('airtable'); | |
const base = new airtable({apiKey: `${process.env.AIRTABLE_API_KEY}`}).base(`${process.env.AIRTABLE_BASE_ID}`); | |
const table = base(`${process.env.AIRTABLE_TABLE_NAME}`); | |
const minifyRecords = (records) => { | |
return records.map((record) => getMinifiedRecord(record)); | |
}; | |
const getMinifiedRecord = (record) => { | |
return { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { table, minifyRecords } from './utils/airtable'; | |
export default async (req, res) => { | |
try { | |
const records = await table.select({}).firstPage(); | |
const minifiedRecords = minifyRecords(records); | |
res.statusCode = 200; | |
res.json(minifiedRecords); | |
} catch (err) { | |
res.statusCode = 500; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {createContext, useState} from 'react'; | |
const DataItemsContext = createContext(); | |
const DataItemsProvider = ({children}) => { | |
const [dataItems, setDataItems] = useState([]); | |
const refreshDataItems = async () => { | |
try { |
OlderNewer