DEV Community 👩‍đŸ’ģ👨‍đŸ’ģ

Cover image for A GitHub Action for Programmer Memes xD
Bhupesh Varshney 👾
Bhupesh Varshney 👾

Posted on • Updated on • Originally published at bhupesh.codes

A GitHub Action for Programmer Memes xD

TLDR;

I created a small github action to greet contributors with random programmer memes

GitHub logo Bhupesh-V / memer-action

A GitHub Action for Programmer Memes xD

Memer Action

memer-action-logo

Github marketplace GitHub release (latest by date) Lint Integration Test Twitter: Bhupesh Varshney

✨ Demo

demomemer

❓ Usage

Example workflow

  • You can use the following workflow as it is, just copy/paste in a file named greetings.yml inside your workflows folder.
  • The reply action is performed by create-or-update-comment
name: Memer Workflow
on: [pull_request]

jobs:
  greeting:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
      - name: Run Memer Action
        id: memer

        uses: Bhupesh-V/memer-action@master
        with:
          filter: "new"

      - name: Check Outputs
        run: |
          echo "${{ steps.memer.outputs.meme }}"
          echo "${{ steps.memer.outputs.title }}"
          echo "${{ steps.memer.outputs.source }}"

      - name: Create comment
        uses: peter-evans/create-or-update-comment@v1.3.0
        id: couc
        with:
          issue-number: ${{ github.event.number }}
          body: |
            🎉🎉 Thanks for opening this PR/Issue 🤗
            Please wait while the maintainer(s) review it

            Meanwhile have a look at this 😝 :

            > **${{ steps.memer.outputs.title }}**
            ![meme](${{ steps.memer.outputs.meme }})
            <sub>ℹī¸ <a href="${{ steps.memer.outputs.source }}">Source</a> [
â€Ļ
Enter fullscreen mode Exit fullscreen mode

View on GitHub Marketplace

Why ?

You can say thanks to contributors by greeting them with some programmer humour & btw almost everyone likes memes so having some fun while contributing to OpenSource would be great :)

Demo

Here is a sample of memer-action in action

How

The action was built using python, here is how the magic happens

import feedparser
import random
import os
import sys

HOST_URL = "https://www.reddit.com/r/ProgrammerHumor"


def getMeme(filter_posts="hot"):
    memelist = []
    memedict = {}
    f = feedparser.parse(f"{HOST_URL}/{filter_posts}.rss")
    for entry in f.entries:
        x = entry['content'][0]['value']
        img = x[x.find("https://i.redd.it"): x.find("link") - 3]
        if img != "":
            memedict["title"] = entry["title"]
            memedict["src"] = str(entry["link"])
            memedict["meme"] = img
            memelist.append(memedict)
        random.shuffle(memelist)
        return memelist[0]


def main():
    filter_by = os.environ["INPUT_FILTER"]
    if filter_by not in ["hot", "top", "new", "rising"]:
        sys.exit(0)
    meme = getMeme(filter_by)
    print(f"::set-output name=meme::{meme['meme']}")
    print(f"::set-output name=title::{meme['title']}")
    print(f"::set-output name=source::{meme['src']}")


if __name__ == "__main__":
    main()

Enter fullscreen mode Exit fullscreen mode

The above script runs inside a docker container. Below are some of the resources that (I used) you can use to build you own actions using Python

have fun !!

Top comments (0)

Join us at DEV

Find what you were looking for? Join hundreds of thousands of developers on DEV so you can:

 
🌚 Enable dark mode
🔠 Change your default font
📚 Adjust your experience level to see more relevant content