Created
August 20, 2024 14:57
-
-
Save Sdy603/99deb14dc8c2d7beb211491fab3f3d62 to your computer and use it in GitHub Desktop.
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 axios = require('axios'); | |
exports.handler = async (event) => { | |
console.log(event); | |
console.log('Received event:', JSON.stringify(event, null, 2)); | |
// Log key-value pairs | |
Object.entries(event).forEach(([key, value]) => { | |
console.log(`${key}: ${value}`); | |
}); | |
// Map Cirrus CI webhook data to the DX Pipelines API fields | |
const pipelineData = { | |
pipeline_name: event.buildConfigurationName, | |
pipeline_source: 'CirrusCI', | |
reference_id: event.taskId, | |
started_at: event.buildCreatedTimestamp, | |
status: event.buildStatus, | |
finished_at: event.buildFinishedTimestamp, | |
repository: event.repository, | |
commit_sha: event.commitSha, | |
pr_number: event.pullRequestNumber, | |
source_url: event.sourceUrl, | |
head_branch: event.branch, | |
email: event.author ? event.author.email : 'N/A', | |
github_username: event.author ? event.author.githubUsername : 'N/A' | |
}; | |
console.log('Mapped pipeline data:', JSON.stringify(pipelineData, null, 2)); | |
// Send a request to the DX Pipelines API | |
try { | |
const response = await axios.post('https://<DX Data Cloud Instance>.getdx.net/api/pipelineRuns.sync', pipelineData, { | |
headers: { | |
'Authorization': `Bearer <DX API Key>`, | |
'Content-Type': 'application/json' | |
} | |
}); | |
console.log('DX API response:', JSON.stringify(response.data, null, 2)); | |
return { | |
statusCode: 200, | |
body: JSON.stringify({ message: 'Request sent successfully', data: response.data }) | |
}; | |
} catch (error) { | |
console.error('Error sending request to DX API:', error.message); | |
return { | |
statusCode: 500, | |
body: JSON.stringify({ message: 'Error sending request', error: error.message }) | |
}; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment