DEV Community

Devansh Maurya
Devansh Maurya

Posted on

Get a custom formatted email message with PR info using Github Actions

My Workflow

I have built my very first Github action from scratch thanks to the Github Actions hackathon by @devteam. The action provides a well-formatted email subject and body using branch name used for Pull Request and other information obtained from the pull request.

I used Javascript to do string processing on the branch name and get a formatted email subject and body with PR info added to it.

The action's inputs and outputs are shown below:

inputs:
  repo-name:
    description: 'Repository name'
    required: true
  groups:
    description: 'Branch groups (as CSV) for which you want to get email message data'
    required: true
  branch-name:
    description: 'Branch name'
    required: true
  pr-title:
    description: 'Pull request title'
  pr-url:
    description: 'Pull request url'
outputs:
  subject:
    description: 'Email subject'
  body:
    description: 'Email body'
Enter fullscreen mode Exit fullscreen mode

With the outputs shown above, you can use them as you like. I use them to send an email on pull requests of specific types using another Github action.

The mail that I received when I opened a PR with branch name pattern/test on the repo Design-Patterns-And-Principles is shown below:

Alt Text

Submission Category:

Maintainer Must-Have

Yaml File or Link to Code

GitHub logo Devansh-Maurya / Get-Email-Message-From-Branch-Action

Provides a well-formatted email subject and body using branch name used for Pull Request and other information obtained from the pull request.

Get custom email message with PR info

Provides a well formated email subject and body using branch name used for Pull Request and other information obtained from the pull request.

Usage

name: Get message
uses: Devansh-Maurya/Get-Email-Message-From-Branch-Action@v3
with:
  repo: ${{ github.repository }}
  groups: group1,gropup2
  branch: ${{ github.event.pull_request.head.ref }}
  pr-title: ${{ github.event.pull_request.title }}
  pr-url: ${{ github.event.pull_request.html_url }}
Enter fullscreen mode Exit fullscreen mode

Documentation

inputs:
  repo-name:
    description: 'Repository name'
    required: true
  groups:
    description: 'Branch groups (as CSV) for which you want to get email message data'
    required: true
  branch-name:
    description: 'Branch name'
    required: true
  pr-title:
    description: 'Pull request title'
  pr-url:
    description: 'Pull request url'
outputs:
  subject:
    description: 'Email subject'
  body:
    description: 'Email body'
Enter fullscreen mode Exit fullscreen mode

Additional Resources / Info

I am using my action in one of my repos that I am building while learning design principles and patterns in object-oriented programming. The repo is kind of a note-taking place where I am implementing each pattern that I study in Kotlin. The action sends a mail whenever a pull request is made to add a new design pattern or design principle. Check it out here:

GitHub logo Devansh-Maurya / Design-Patterns-And-Principles

A collection of a number of design patterns and principles written in Kotlin

A collection of design patterns and principles written in Kotlin

What are Design Principles?

A design principle is a basic tool or technique that can be applied to designing or writing code to make that code more maintainable, flexible, or extensible.

Explore the Design Principles in this repo

What are Design Patterns?

A design pattern is a solution to a problem in a context.

  • The context is the situation in which the pattern applies. This should be a recurring situation.
  • The problem refers to the goal you are trying to achieve in this context, but it also refers to any constraints that occur in the context.
  • The solution is what you’re after: a general design that anyone can apply which resolves the goal and set of constraints.

If you find yourself in a context with a problem that has a goal that is affected by a set of constraints, then…

Hope you liked it. Thanks for reading.

Top comments (0)