├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── ----bug-report.md │ ├── ---feature-request.md │ └── ---say-thank-you.md ├── PULL_REQUEST_TEMPLATE │ └── pull_request_template.md └── workflows │ ├── greetings.yml │ ├── integration.yml │ └── python.yml ├── CONTRIBUTING.md ├── Dockerfile ├── LICENSE ├── README.md ├── action.yml ├── images └── header.png └── main.py /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | open_collective: # Replace with a single Open Collective username 5 | ko_fi: bhupesh 6 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 7 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 8 | issuehunt: # Replace with a single IssueHunt username 9 | otechie: # Replace with a single Otechie username 10 | custom: https://paypal.me/BhupeshVarshney 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/----bug-report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F41B Bug report" 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: 'bug' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. Ubuntu] 28 | - Python Version [e.g. 3.8] 29 | - Memer Action Version [e.g. 0.2.0] 30 | 31 | **Additional context** 32 | Add any other context about the problem here. 33 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/---feature-request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F680 Feature request" 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: 'enhancement' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/---say-thank-you.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F49F Say thank you" 3 | about: Just say thanks if you liked memer-action 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | if you liked **memer-action** - please let us know. We'd love to hear from you! 11 | 12 | You can help me in any way possible 13 | 14 | - [ ] Give the repository a star ⭐️. 15 | - [ ] Help out with issues. 16 | - [ ] Share it with others. 17 | - [ ] Buy me a [ko-fi](https://ko-fi.com/bhupesh). 18 | 19 | Thank you! 💐 20 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Solved/Fixed : #issue-no 6 | 7 | > 8 | - 9 | - 10 | - 11 | 12 | 13 | 14 | - [] Did you read the `CONTRIBUTING` Guidelines before creating this PR ? 15 | -------------------------------------------------------------------------------- /.github/workflows/greetings.yml: -------------------------------------------------------------------------------- 1 | name: Memer Greetings 2 | 3 | on: [pull_request] 4 | 5 | jobs: 6 | greeting: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v2 10 | - name: Self test 11 | id: selftest 12 | 13 | uses: Bhupesh-V/memer-action@master 14 | with: 15 | filter: "new" 16 | 17 | - name: Check outputs 18 | run: | 19 | echo "${{ steps.selftest.outputs.meme }}" 20 | echo "${{ steps.selftest.outputs.title }}" 21 | echo "${{ steps.selftest.outputs.source }}" 22 | 23 | - name: Create comment 24 | uses: peter-evans/create-or-update-comment@v1.4.2 25 | id: couc 26 | with: 27 | issue-number: ${{ github.event.number }} 28 | body: | 29 | 🎉🎉 Thanks for opening this PR/Issue 🤗 30 | Please wait while the maintainer(s) review it 31 | 32 | Meanwhile have a look at this meme 😝 : 33 | 34 | > **${{ steps.selftest.outputs.title }}** 35 | ![meme](${{ steps.selftest.outputs.meme }}) 36 | ℹ️ Source [ Powered By 🔥 Memer Action ] 37 | -------------------------------------------------------------------------------- /.github/workflows/integration.yml: -------------------------------------------------------------------------------- 1 | name: Integration Test 2 | on: [push] 3 | jobs: 4 | build: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: actions/checkout@v2 8 | - name: Self test 9 | id: selftest 10 | 11 | uses: Bhupesh-V/memer-action@master 12 | with: 13 | filter: "new" 14 | 15 | - name: Check outputs 16 | run: | 17 | echo "${{ steps.selftest.outputs.meme }}" 18 | echo "${{ steps.selftest.outputs.title }}" 19 | echo "${{ steps.selftest.outputs.source }}" 20 | -------------------------------------------------------------------------------- /.github/workflows/python.yml: -------------------------------------------------------------------------------- 1 | name: Lint 2 | on: [push, pull_request] 3 | jobs: 4 | lint: 5 | name: Lint 6 | runs-on: ubuntu-latest 7 | steps: 8 | - name: Set up Python 3.8 9 | uses: actions/setup-python@v2 10 | with: 11 | python-version: "3.8" 12 | 13 | - uses: actions/checkout@v2 14 | 15 | - name: Lint 16 | run: | 17 | pip install black 18 | black --check --diff main.py 19 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Memer Action xD 2 | 3 | :tada: First of all, thanks for taking the time to contribute! :tada: 4 | 5 | Make sure you follow below guidelines before contributing. 6 | 7 | 1. Raise an issue before sending any PR (if the issue doesn't exist). 8 | 2. Make you changes to `feature` branch. 9 | 3. See if there is already an [open PR](https://github.com/Bhupesh-V/memer-action/pulls) for the same issue. 10 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3-slim AS builder 2 | ADD . /app 3 | WORKDIR /app 4 | 5 | # We are installing a dependency here directly into our app source dir 6 | RUN pip install --target=/app feedparser 7 | 8 | # A distroless container image with Python and some basics like SSL certificates 9 | # https://github.com/GoogleContainerTools/distroless 10 | FROM gcr.io/distroless/python3-debian10 11 | COPY --from=builder /app /app 12 | WORKDIR /app 13 | ENV PYTHONPATH /app 14 | CMD ["/app/main.py"] 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2020 GitHub, Inc. and contributors 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 |

Memer Action

3 |

4 | memer-action-logo 5 |

6 |

7 | 8 | [![Github marketplace](https://img.shields.io/badge/Marketplace-Memer%20Action-blue.svg?colorA=24292e&colorB=0366d6&style=flat&longCache=true&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAM6wAADOsB5dZE0gAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAERSURBVCiRhZG/SsMxFEZPfsVJ61jbxaF0cRQRcRJ9hlYn30IHN/+9iquDCOIsblIrOjqKgy5aKoJQj4O3EEtbPwhJbr6Te28CmdSKeqzeqr0YbfVIrTBKakvtOl5dtTkK+v4HfA9PEyBFCY9AGVgCBLaBp1jPAyfAJ/AAdIEG0dNAiyP7+K1qIfMdonZic6+WJoBJvQlvuwDqcXadUuqPA1NKAlexbRTAIMvMOCjTbMwl1LtI/6KWJ5Q6rT6Ht1MA58AX8Apcqqt5r2qhrgAXQC3CZ6i1+KMd9TRu3MvA3aH/fFPnBodb6oe6HM8+lYHrGdRXW8M9bMZtPXUji69lmf5Cmamq7quNLFZXD9Rq7v0Bpc1o/tp0fisAAAAASUVORK5CYII=)](https://github.com/marketplace/actions/memer-action) 9 | [![GitHub release (latest by date)](https://img.shields.io/github/v/release/bhupesh-v/memer-action?logo=GitHub)](https://github.com/Bhupesh-V/memer-action/releases) 10 | [![Lint](https://github.com/Bhupesh-V/memer-action/workflows/Lint/badge.svg?branch=master)](https://github.com/Bhupesh-V/memer-action/actions?query=workflow%3ALint) 11 | [![Integration Test](https://github.com/Bhupesh-V/memer-action/workflows/Integration%20Test/badge.svg?branch=master)](https://github.com/Bhupesh-V/memer-action/actions?query=workflow%3A%22Integration+Test%22) 12 | 13 | Twitter: Bhupesh Varshney 14 | 15 | 16 | ## ✨ Demo 17 | 18 | ![demomemer](https://user-images.githubusercontent.com/34342551/79064573-a6fa9e80-7cc7-11ea-895e-6538c2b8548b.png) 19 | 20 | ## ❓ Usage 21 | 22 | ### Example workflow 23 | 24 | - You can use the following workflow as it is, just copy/paste in a file named `greetings.yml` inside your [workflows](https://github.com/Bhupesh-V/memer-action/tree/master/.github/workflows) folder. 25 | - The reply action is performed by [create-or-update-comment](https://github.com/peter-evans/create-or-update-comment) 26 | 27 | ```yaml 28 | name: Memer Workflow 29 | 30 | on: [pull_request] 31 | 32 | jobs: 33 | greeting: 34 | runs-on: ubuntu-latest 35 | steps: 36 | - uses: actions/checkout@master 37 | - name: Run Memer Action 38 | id: memer 39 | 40 | uses: Bhupesh-V/memer-action@master 41 | with: 42 | filter: "new" 43 | 44 | - name: Check Outputs 45 | run: | 46 | echo "${{ steps.memer.outputs.meme }}" 47 | echo "${{ steps.memer.outputs.title }}" 48 | echo "${{ steps.memer.outputs.source }}" 49 | 50 | - name: Create comment 51 | uses: peter-evans/create-or-update-comment@v1.3.0 52 | id: couc 53 | with: 54 | issue-number: ${{ github.event.number }} 55 | body: | 56 | 🎉🎉 Thanks for opening this PR/Issue 🤗 57 | Please wait while the maintainer(s) review it 58 | 59 | Meanwhile have a look at this 😝 : 60 | 61 | > **${{ steps.memer.outputs.title }}** 62 | ![meme](${{ steps.memer.outputs.meme }}) 63 | ℹ️ Source [ Powered By 🔥 Memer Action ] 64 | 65 | ``` 66 | 67 | ### Inputs 68 | 69 | Memer Action accepts following input variables. 70 | 71 | - `filter` (optional) : Sort Memes posts from reddit. Only 4 values are acceptable, **hot**, **top**, **new** & **rising**. By default the memes are "hot". 72 | - `fallback` (optional) : A JSON string for showing a Fallback meme, in case there are no memes available. By default the fallback output is 73 | ```python 74 | FALLBACK = { 75 | "meme_link": "https://raw.githubusercontent.com/Bhupesh-V/memer-action/master/images/header.png", 76 | "title": "Oops :( looks like we are out of memes.", 77 | "src": "https://github.com/Bhupesh-V/memer-action", 78 | } 79 | ``` 80 | 81 | ```yaml 82 | steps: 83 | - uses: actions/checkout@master 84 | - name: Run action 85 | id: myaction 86 | 87 | uses: Bhupesh-V/memer-action@master 88 | with: 89 | filter: new 90 | fallback: '{"meme_link":"", "title": "", "src": ""}' 91 | 92 | - name: Check outputs 93 | run: | 94 | echo "Outputs - ${{ steps.myaction.outputs.title }}" 95 | echo "Outputs - ${{ steps.myaction.outputs.meme }}" 96 | echo "Outputs - ${{ steps.myaction.outputs.source }}" 97 | ``` 98 | 99 | ### Outputs 100 | 101 | Memer Action sets 3 outputs. 102 | 103 | - `title`: The title of the post on reddit 104 | - `meme`: The meme image link 105 | - `source`: The Source of the Meme (post on reddit) 106 | 107 | ```yaml 108 | steps: 109 | - uses: actions/checkout@master 110 | - name: Run action 111 | id: myaction 112 | 113 | uses: Bhupesh-V/memer-action@master 114 | 115 | - name: Check outputs 116 | run: | 117 | echo "Outputs - ${{ steps.myaction.outputs.title }}" 118 | echo "Outputs - ${{ steps.myaction.outputs.meme }}" 119 | echo "Outputs - ${{ steps.myaction.outputs.source }}" 120 | ``` 121 | 122 | Note: This action does not work in `pull_request` workflows when triggered by a fork opening a pull request in the upstream repository. 123 | This is due to restrictions put in place by GitHub Actions. See [here](https://github.com/peter-evans/create-pull-request/blob/master/docs/concepts-guidelines.md#restrictions-on-forked-repositories) for further explanation. 124 | 125 | ## 💙 Credits 126 | - [create-or-update-comment](https://github.com/peter-evans/create-or-update-comment) 127 | - [python-container-action](https://github.com/jacobtomlinson/python-container-action) 128 | 129 | ## ☺️ Show your support 130 | 131 | Support me by giving a ⭐️ if this project helped you! or just [![Twitter URL](https://img.shields.io/twitter/url?label=Tweet%20Memer%20Action&logoColor=blue&style=social&url=https%3A%2F%2Ftwitter.com%2Fintent%2Ftweet%3Furl%3Dhttps%3A%2F%2Fgithub.com%2FBhupesh-V%2Fmemer-action%26text%3DA%2520GitHub%2520Action%2520for%2520programmer%2520memes%2520%3B%29)](https://twitter.com/intent/tweet?url=https://github.com/Bhupesh-V/memer-action&text=A%20GitHub%20Action%20for%20programmer%20memes) 132 | 133 | ## 📝 License 134 | 135 | Copyright © 2020 [Bhupesh Varshney](https://github.com/Bhupesh-V).
136 | This project is [MIT](https://github.com/Bhupesh-V/memer-action/blob/master/LICENSE) licensed. 137 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: "Memer Action" 2 | description: "A GitHub Action for Programmer Memes" 3 | author: "Bhupesh Varshney" 4 | inputs: 5 | filter: 6 | description: "Sort posts on reddit by (hot, new, top & rising) by default hot" 7 | required: false 8 | outputs: 9 | title: 10 | description: "The Post Title" 11 | source: 12 | description: "The Source of the meme, Reddit Post Link" 13 | meme: 14 | description: "The Meme Image Link" 15 | runs: 16 | using: "docker" 17 | image: "Dockerfile" 18 | branding: 19 | icon: 'wind' 20 | color: 'blue' -------------------------------------------------------------------------------- /images/header.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bhupesh-V/memer-action/44c4349aec750197d2ee18e98a926ef236d4f4c2/images/header.png -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import feedparser 2 | import random 3 | import os 4 | import sys 5 | import json 6 | 7 | SUB_URL = "https://www.reddit.com/r/ProgrammerHumor" 8 | FALLBACK = { 9 | "meme_link": "https://raw.githubusercontent.com/Bhupesh-V/memer-action/master/images/header.png", 10 | "title": "Oops :( looks like we are out of memes.", 11 | "src": "https://github.com/Bhupesh-V/memer-action", 12 | } 13 | 14 | 15 | def getMeme(filter_posts="hot"): 16 | memelist = [] 17 | memedict = {} 18 | f = feedparser.parse(f"{SUB_URL}/{filter_posts}.rss") 19 | for entry in f.entries: 20 | post_content = entry["content"][0]["value"] 21 | img = post_content[ 22 | post_content.find("https://i.redd.it") : post_content.find("link") - 3 23 | ] 24 | if img != "": 25 | memedict["title"] = entry["title"] 26 | memedict["src"] = str(entry["link"]) 27 | memedict["meme_link"] = img 28 | memelist.append(memedict) 29 | 30 | if len(memelist) != 0: 31 | random.shuffle(memelist) 32 | # elif os.environ["INPUT_FALLBACK"]: 33 | # fallback_dict = json.loads(os.environ["INPUT_FALLBACK"]) 34 | # if FALLBACK.keys() == fallback_dict.keys(): 35 | # memelist.append(fallback_dict) 36 | # else: 37 | # print("Key Error, make sure keys are", FALLBACK.keys()) 38 | # sys.exit(0) 39 | else: 40 | memelist.append(FALLBACK) 41 | 42 | return memelist[0] 43 | 44 | 45 | def main(): 46 | filter_by = os.environ["INPUT_FILTER"] 47 | if filter_by not in ["hot", "top", "new", "rising"]: 48 | print("filter must be one of hot, top, new or rising") 49 | sys.exit(0) 50 | meme = getMeme(filter_by) 51 | print(f"::set-output name=meme::{meme['meme_link']}") 52 | print(f"::set-output name=title::{meme['title']}") 53 | print(f"::set-output name=source::{meme['src']}") 54 | 55 | 56 | if __name__ == "__main__": 57 | main() 58 | --------------------------------------------------------------------------------