Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automating the process #32

Open
alicanbatur opened this issue Nov 26, 2018 · 1 comment
Open

Automating the process #32

alicanbatur opened this issue Nov 26, 2018 · 1 comment
Labels
enhancement New feature or request

Comments

@alicanbatur
Copy link
Contributor

Sharing a tip after it has been added should be automated.

@alicanbatur alicanbatur added the enhancement New feature or request label Nov 26, 2018
@hkan
Copy link

hkan commented Nov 29, 2018

I've done a little research and came up with this pseudo(javascript)code to use with GitHub Webhooks. It only includes Twitter status updates because AFAIK Instagram does not have a public API to allow posting images. I can build a fully functional script to run on Amazon Lambda or similar if it is indeed what you guys need.

// const repo = magical GitHub API object

async function handleGithubPushEvent(pushEventData) {

    // See [1] below
    const masterWantsUsToShare = pushEventData.commits.some(commit =>
        commit.message.contains('!share')
    );

    if (!masterWantsUsToShare) {
        return;
    }

    // See [2] below
    const tree = await repo.getTree('/');

    const latestCodeDirectory = tree.sortByNameDesc()
        .find(directory => directory.isCodeDirectory);

    // See [3] below
    const meta = await.repo.getFile(latestCodeDirectory.path + '/meta.json');
    const image = await.repo.getFile(latestCodeDirectory.path + '/screenshot.png');

    // See [4] below
    const mediaID = await twitterAPI.uploadMedia(image);

    // See [5] below
    await twitterAPI.postTweet({
        tweet: meta.tweet,
        media: mediaID,
    });
}

Further read:
[1] GitHub webhooks — push event: https://developer.github.com/v3/activity/events/types/#pushevent
[2] GitHub API — tree traversal: https://developer.github.com/v3/git/trees/
[3] GitHub API — file handling: https://developer.github.com/v3/git/blobs/
[4] Twitter API — media upload: https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-upload.html
[5] Twitter API — status update: https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-update

Note on Instagram: There are private API implementations around but I don't know what risks they might bring up. See for yourself and take your chances if you'd like 😛 https://github.com/huttarichard/instagram-private-api

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants