Created
March 18, 2018 14:48
-
-
Save ramdesh/f0af488a9851f424b9211997f841ace7 to your computer and use it in GitHub Desktop.
Lambda Telegram Trigger
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
var http = require('https'); | |
var AWS = require('aws-sdk'); | |
exports.handler = (event, context) => { | |
var codecommit = new AWS.CodeCommit({ apiVersion: '2015-04-13' }); | |
var baseUrl = "https://api.telegram.org/bot416356188:AAGaWMHjEXsxTmXb4c6GAsIkLbpwpWMUMzs/sendMessage?chat_id=-283837997&text="; | |
//Log the updated references from the event | |
var commits = event.Records[0].codecommit.references.map( | |
function(reference) { | |
return reference.commit; | |
}); | |
console.log(event.Records[0].codecommit.references); | |
console.log('CommitId:', commits); | |
//Get the repository from the event and show its git clone URL | |
var repository = event.Records[0].eventSourceARN.split(":")[5]; | |
codecommit.getCommit({ | |
commitId: commits[0], | |
repositoryName: repository | |
}, function(err, data) { | |
if(err) { | |
context.fail(err); | |
} else { | |
console.log(data); | |
var commit = data.commit; | |
var commitDetails = 'New commit to Modjoul API repo: \nRef: ' + event.Records[0].codecommit.references[0].ref | |
+ '\n' + 'Message: ' + commit.message + 'Author: ' + commit.author.name + ' <' + commit.author.email + '>'; | |
var url = baseUrl + commitDetails; | |
http.get(url, function(res) { | |
console.log("Success"); | |
context.succeed(); | |
}).on('error', function(e) { | |
console.log("Failed"); | |
context.fail(); | |
}); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment