Skip to content

Commit 5216208

Browse files
authored
Implements Slack notifications (#62)
* ci(upstream): add Slack notification workflow - Creates workflow to send notification to Slack channel after merging PR * ci(upstream): fixes Slack notification workflow * ci(upstream): improve Slack notification formatting * ci(upstream): fix notification formatting * ci(upstream): add formatting changes * ci(upstream): improve notification formatting * ci(upstream): fix notification formatting * docs(upstream): updates READMEs - Updates instructions for Spring Boot and Software Development Processes modules * ci(upstream): attempt fix for YAML issues - Adds spacing to changed files list to fix indentation error - Tweaks README to test multiple changed files * ci(upstream): add more YAML fixes - Add content tweak to README.md for multiline comment * ci(upstream): splits multi-line commit messages - Takes first line as the title and any subsequent lines as the description * ci(upstream): exclude blank description fields * ci(upstream): displays changed files as list * ci(upstream): fix file list formatting * ci(upstream): fix list bullet points * ci(upstream): prevents merge commit notifications * ci(upstream): enable description formatting - Removes blockquoting for description field - Enables Markdown formatting for PRs * ci(upstream): tweak comments * revert(upstream): revert 5854af4 - Reverts previous commit * ci(upstream): improve description formatting ## Main changes - enables *Markdown* descriptions - simplifies formatting logic ## Notes This should now be formatted * ci(upstream): renames workflow ## Main changes - renames workflow ## Notes Just another commit to test notification formatting
1 parent 459f0fc commit 5216208

File tree

3 files changed

+113
-43
lines changed

3 files changed

+113
-43
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Notify Slack
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- main
8+
push:
9+
branches:
10+
- main
11+
12+
jobs:
13+
notify-slack:
14+
if: |
15+
(github.event_name == 'pull_request' && github.event.pull_request.merged == true && success()) ||
16+
(github.event_name == 'push' && !contains(github.event.head_commit.message, 'Merge pull request') && success())
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Get changes
25+
id: get-changes
26+
run: |
27+
if [ "${{ github.event_name }}" = "pull_request" ]; then
28+
# Get PR changes
29+
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | sed '2,$s/^/ • /')
30+
DESCRIPTION=$(echo "${{ github.event.pull_request.body }}" | sed 's/"/\\"/g' | awk '{printf "%s\\n", $0}')
31+
TITLE=$(echo "${{ github.event.pull_request.title }}" | sed 's/"/\\"/g' | sed '2,$s/^/ /')
32+
AUTHOR="${{ github.event.pull_request.user.login }}"
33+
URL="${{ github.event.pull_request.html_url }}"
34+
else
35+
# Get push changes
36+
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | sed '2,$s/^/ • /')
37+
38+
# Split commit message into title and description
39+
COMMIT_MSG="${{ github.event.head_commit.message }}"
40+
TITLE=$(echo "$COMMIT_MSG" | head -n1 | sed 's/"/\\"/g')
41+
DESCRIPTION=$(echo "$COMMIT_MSG" | tail -n +2 | sed '/./,$!d' | sed 's/"/\\"/g' | awk '{printf "%s\\n", $0}')
42+
43+
AUTHOR="${{ github.event.head_commit.author.username }}"
44+
URL="${{ github.event.head_commit.url }}"
45+
fi
46+
47+
echo "changed_files<<EOF" >> $GITHUB_OUTPUT
48+
echo "$CHANGED_FILES" >> $GITHUB_OUTPUT
49+
echo "EOF" >> $GITHUB_OUTPUT
50+
51+
echo "description=$DESCRIPTION" >> $GITHUB_OUTPUT
52+
echo "title=$TITLE" >> $GITHUB_OUTPUT
53+
echo "author=$AUTHOR" >> $GITHUB_OUTPUT
54+
echo "url=$URL" >> $GITHUB_OUTPUT
55+
56+
- name: Send to Slack
57+
if: success()
58+
uses: slackapi/slack-github-action@v2.0.0
59+
with:
60+
method: chat.postMessage
61+
token: ${{ secrets.SLACK_BOT_TOKEN }}
62+
payload: |
63+
channel: ${{ vars.SLACK_CHANNEL_ID }}
64+
text: "GitHub Action build result: ${{ job.status }}\n${{ steps.get-changes.outputs.url }}"
65+
blocks:
66+
- type: header
67+
text:
68+
type: plain_text
69+
text: "🎉 Repo Updated! 🎉"
70+
emoji: true
71+
- type: section
72+
text:
73+
type: mrkdwn
74+
text: "<https://github.com/${{ steps.get-changes.outputs.author }}|${{ steps.get-changes.outputs.author }}> contributed <${{ steps.get-changes.outputs.url }}|${{ steps.get-changes.outputs.title }}>"
75+
${{ steps.get-changes.outputs.description != '' && steps.get-changes.outputs.description != null && format('- type: section
76+
text:
77+
type: mrkdwn
78+
text: "{0}"', steps.get-changes.outputs.description) || '' }}
79+
- type: section
80+
text:
81+
type: mrkdwn
82+
text: |
83+
*Changed Files:*
84+
• ${{ steps.get-changes.outputs.changed_files }}

exercises/software-dev-processes/README.md

Lines changed: 21 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,19 @@
1-
# The Calculator
1+
# Software Development Processes
22

3-
[![Java Language](https://img.shields.io/badge/language-Java-3A75B0.svg?logo=OpenJDK)][1]
4-
[![JVM Platform](https://img.shields.io/badge/platform-JVM-6C93B8.svg?logo=IntelliJIDEA)][2]
5-
[![JUnit5 Testing Framework](https://img.shields.io/badge/testing%20framework-JUnit5-26A162.svg?logo=JUnit5)][3]
6-
[![Maven Dependency Manager](https://img.shields.io/badge/dependency%20manager-Maven-AA215A.svg?logo=ApacheMaven)][4]
3+
[![Java Language](https://img.shields.io/badge/PLATFORM-OpenJDK-3A75B0.svg?style=for-the-badge)][1]
4+
[![JUnit5 Testing Framework](https://img.shields.io/badge/testing%20framework-JUnit5-26A162.svg?style=for-the-badge)][2]
5+
[![Maven Dependency Manager](https://img.shields.io/badge/dependency%20manager-Maven-AA215A.svg?style=for-the-badge)][3]
76

87
A simple project to practice writing JUnit 5 tests.
98

109
This short guide describes:
1110

12-
- [Prerequisites][5]
13-
- [Development Setup][6]
14-
- [JUnit 5 Exercise][7]
11+
- [Getting Started][4]
12+
- [Exercise 1][5]
13+
- [Exercise 2][6]
14+
- [Exercise 3][7]
1515

16-
## Prerequisites
17-
18-
This starter project uses the [Java][1] programming language.
19-
20-
Before getting started, ensure you have Java 17 LTS (or higher) installed locally. The following commands should output the version of Java installed.
21-
22-
```bash
23-
$ javac -version
24-
25-
javac 17.0.4
26-
```
27-
28-
29-
```bash
30-
$ java -version
31-
32-
openjdk version "17.0.4" 2022-07-19 LTS
33-
OpenJDK Runtime Environment Zulu17.36+13-CA (build 17.0.4+8-LTS)
34-
OpenJDK 64-Bit Server VM Zulu17.36+13-CA (build 17.0.4+8-LTS, mixed mode, sharing)
35-
```
36-
37-
#### <u>Install dependencies</u>
16+
## Getting Started
3817

3918
In your terminal, navigate to the `software-dev-processes` directory, then run the following command to compile the application:
4019

@@ -72,9 +51,7 @@ Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/
7251
[INFO] ------------------------------------------------------------------------
7352
```
7453

75-
## Practice
76-
77-
#### Exercise 1
54+
## Exercise 1
7855

7956
Examine the class implemented in `src/main/java/com/cbfacademy/Calculator.java`.
8057
Create a test class at `src/test/java/com/cbfacademy/CalculatorTest.java`.
@@ -99,7 +76,7 @@ mvnw clean test -Dtest=CalculatorTest#testAddition
9976

10077
Once all your tests are passing, commit your changes.
10178

102-
#### Exercise 2
79+
## Exercise 2
10380

10481
Write tests to ensure the Calculator can divide two numbers.\
10582
Think of all possible scenarios, and write a test for each of the scenarios.\
@@ -117,17 +94,18 @@ mvnw clean test -Dtest=CalculatorTest#testDivision
11794

11895
Once all your tests are passing, commit your changes.
11996

120-
#### Exercise 3
121-
Add more scenarios to cover the Calculator's addition and subtraction functionalities.
97+
## Exercise 3
98+
99+
Add more scenarios to cover the calculator's addition and subtraction functionalities.
122100

123101
Once all your tests are passing, commit your changes and push your branch to GitHub.
124102

125103
Enjoy working on your exercise! :smiley:
126104

127-
[1]: https://www.java.com/en/download/help/whatis_java.html
128-
[2]: https://www.ibm.com/cloud/blog/jvm-vs-jre-vs-jdk
129-
[3]: https://junit.org/junit5/
130-
[4]: https://maven.apache.org/
131-
[5]: #prerequisites
132-
[6]: #development-setup
133-
[7]: #practice
105+
[1]: https://docs.oracle.com/javase/21/docs/api/index.html
106+
[2]: https://junit.org/junit5/
107+
[3]: https://maven.apache.org/
108+
[4]: #getting-started
109+
[5]: #exercise-1
110+
[6]: #exercise-2
111+
[7]: #exercise-3

exercises/spring-boot/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Spring Boot
22

3+
[![Java Language](https://img.shields.io/badge/PLATFORM-OpenJDK-3A75B0.svg?style=for-the-badge)][1]
4+
[![JUnit5 Testing Framework](https://img.shields.io/badge/testing%20framework-JUnit5-26A162.svg?style=for-the-badge)][2]
5+
[![Maven Dependency Manager](https://img.shields.io/badge/dependency%20manager-Maven-AA215A.svg?style=for-the-badge)][3]
6+
37
## Description
48

59
The goal of these exercises is to build a RESTful API service that allows users to manage IOUs (I Owe You agreements) using Spring Boot.
@@ -186,3 +190,7 @@ Modify the `/api/ious` endpoint to filter IOUs for a specific lender, defined as
186190
- :sos: Ask. :clap: For. :clap: Help! :clap: Your mentors, instructors and assistants are literally here to support you, so *make use of them* - don't sit and struggle in silence.
187191

188192
Best of luck! Remember, it's not just about the destination; it's the journey. Happy coding! 🚀
193+
194+
[1]: https://docs.oracle.com/javase/21/docs/api/index.html
195+
[2]: https://junit.org/junit5/
196+
[3]: https://maven.apache.org/

0 commit comments

Comments
 (0)