Skip to content

Instantly share code, notes, and snippets.

View itaditya's full-sized avatar
🎯
Focusing

Aditya Agarwal itaditya

🎯
Focusing
View GitHub Profile
const features = await getFeatures();
/*
{
showNewStyle: false,
allowNewsFeedAccess: true
}
*/
if (features.showNewStyle) {
userComments = comments
.filter(comment => comment.user.login === username)
context.github.issues.create({
owner: 'org-name',
repo: 'maintainers-discussion',
title: `${username}-discussion`,
body: `@${username} has been found out to be hostile in the past.
This issue is opened so that maintainers can discuss about it.`
})
module.exports = robot => {
const remindUserToCode = async() => {
robot.log('remindUserToCode')
const installation_id = 116342
const github = await robot.auth(installation_id);
const yesterdayDate = getYesterdayDate();
const { data:{ total_count:total_commits }} = await github.search.commits({
q: `author:itaditya author-date:>${yesterdayDate}`
});
console.log('total_commits', total_commits)
@itaditya
itaditya / comments.module.js
Last active March 26, 2018 23:17
Example implementation for test driven development
const getIssues = require('./getIssues')
module.exports = (context) => {
const issues = await getIssues(context.github)
// do other things with this
}
// This is the comments module and will use utils like getIssues to perform the whole task
context.github.search.issues({
q: `commenter:${username}`
})
context.github.issues.getComments({
owner,
repo,
number: issueNum
})
@itaditya
itaditya / baduse-example-2.js
Created March 31, 2018 21:22
Snippet for Avoiding the async/await hell medium article
async function orderItems() {
const items = await getCartItems() // async call
const noOfItems = items.length
for(var i = 0; i < noOfItems; i++) {
await sendRequest(items[i]) // async call
}
}
@itaditya
itaditya / func-without-await.js
Last active March 31, 2018 22:14
async function without await
(async () => {
const value = doSomeAsyncTask()
console.log(value) // an unresolved promise
})()
@itaditya
itaditya / func-with-await.js
Created March 31, 2018 22:15
async function with await
(async () => {
const promise = doSomeAsyncTask()
const value = await promise
console.log(value) // the actual value
})()