Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* senzing-factory/build-resources#69 add linting

* update linting errors

* update linting errors

* casing

* cleanup

* Fix http request

---------

Co-authored-by: docktermj <michael@dockter.com>
  • Loading branch information
kernelsam and docktermj committed Feb 23, 2024
1 parent aa57496 commit fef7e58
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 24 deletions.
1 change: 1 addition & 0 deletions .github/linters/.hadolint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
failure-threshold: error
3 changes: 3 additions & 0 deletions .github/linters/.markdown-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"line-length": false
}
9 changes: 9 additions & 0 deletions .github/linters/.yaml-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Extends the default yamllint config by adjusting some options.
extends: default

rules:
comments-indentation: disable
line-length:
level: warning
allow-non-breakable-inline-mappings: true
truthy: disable
2 changes: 1 addition & 1 deletion .github/workflows/add-labels-standardized.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'add labels standardized'
name: add labels standardized

on:
issues:
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/add-to-project-factory-dependabot.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
name: 'add to project factory dependabot'
name: add to project factory dependabot

on:
pull_request:
branches: [main]

jobs:

add-issue-labels:
add-to-project-dependabot:
secrets:
SENZING_GITHUB_PROJECT_RW_TOKEN: ${{ secrets.SENZING_GITHUB_PROJECT_RW_TOKEN }}
uses: senzing-factory/build-resources/.github/workflows/add-to-project-dependabot.yaml@main
uses: senzing-factory/build-resources/.github/workflows/add-to-project-dependabot.yaml@v1
with:
project: ${{ vars.SENZING_PROJECT_FACTORY }}
9 changes: 5 additions & 4 deletions .github/workflows/add-to-project-factory.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'add to project factory'
name: add to project factory

on:
issues:
Expand All @@ -8,11 +8,12 @@ on:

jobs:
add-to-project:
name: Add issue to project
name: add issue to project
runs-on: ubuntu-latest

steps:
- name: Assign issue to project
- name: assign issue to project
uses: actions/add-to-project@v0.5.0
with:
project-url: https://github.com/orgs/${{ vars.SENZING_GITHUB_ACCOUNT_NAME }}/projects/${{ vars.SENZING_PROJECT_FACTORY }}
github-token: ${{ secrets.SENZING_GITHUB_ACCESS_TOKEN }}
project-url: https://github.com/orgs/${{ vars.SENZING_GITHUB_ACCOUNT_NAME }}/projects/${{ vars.SENZING_PROJECT_FACTORY }}
15 changes: 11 additions & 4 deletions .github/workflows/docker-build-container.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
name: 'docker build container'
name: docker build container

on: [push]

jobs:
docker-build-container:
runs-on: ubuntu-latest

steps:
- name: Build docker image
uses: Senzing/github-action-docker-buildx-build@v1
- name: get repo name
id: repo-basename
run: |
echo "repo=$(basename ${{ github.repository }})" >> "$GITHUB_OUTPUT"
shell: bash

- name: build docker image
uses: senzing-factory/github-action-docker-buildx-build@v1
with:
build-options: "--build-arg \"GITHUB_HEAD_REF=${GITHUB_HEAD_REF:-${GITHUB_REF##*/}}\" \
--build-arg \"GITHUB_EVENT_NAME=${GITHUB_EVENT_NAME}\" "
context: build/docker
image-repository: senzing-factory/git-action-slack-notification
image-repository: senzing-factory/${{ steps.repo-basename.outputs.repo }}
image-tag: ${{ github.ref_name }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
11 changes: 11 additions & 0 deletions .github/workflows/lint-repo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: lint repo

on:
push:
branches-ignore: [main]
pull_request:
branches: [main]

jobs:
lint-code-base:
uses: senzing-factory/build-resources/.github/workflows/linter.yaml@v1
14 changes: 14 additions & 0 deletions .github/workflows/move-pr-to-done-dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: move pr to done dependabot

on:
pull_request:
branches: [main]
types: [closed]

jobs:
move-pr-to-done-dependabot:
secrets:
SENZING_GITHUB_PROJECT_RW_TOKEN: ${{ secrets.SENZING_GITHUB_PROJECT_RW_TOKEN }}
uses: senzing-factory/build-resources/.github/workflows/move-pr-to-done-dependabot.yaml@v1
with:
project: ${{ vars.SENZING_PROJECT_FACTORY }}
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Project maintainers have the right and responsibility to remove, edit, or reject

## Scope

This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project email address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.

## Enforcement

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Go [here](deployment/git-actions/template_git_action_slack_notification.yml) for
3\. Generate Slack WebHook [here](https://entelexeia.slack.com/apps/A0F7XDUAZ-incoming-webhooks?next_id=0)
4\. Encrypt Slack Webhook as a secret in the repo using this app.
4\. Encrypt Slack Webhook as a secret in the repository using this app.
## Environment Variables
Expand Down
4 changes: 2 additions & 2 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Config struct {
SlackWebhook string
SlackTitle string
SlackMessage string
SlackIconUrl string
SlackIconURL string
SlackChannel string
SlackColor string
SlackUsername string
Expand Down Expand Up @@ -45,7 +45,7 @@ func (config *Config) Init() error {
}

// Setting unrequired environment variables
config.SlackIconUrl = os.Getenv("SLACK_ICON")
config.SlackIconURL = os.Getenv("SLACK_ICON")
config.SlackChannel = os.Getenv("SLACK_CHANNEL")
config.SlackColor = os.Getenv("SLACK_COLOR")
config.SlackUsername = os.Getenv("SLACK_USERNAME")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
SLACK_MESSAGE: Demo'ing the Slack Notification
SLACK_TITLE: Slack Notification Demo
SLACK_USERNAME: demo-bot
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
20 changes: 14 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package main

import (
"github.com/pkg/errors"
"github.com/senzing/git-action-slack-notification/configuration"
"log"
"bytes"
"encoding/json"
"fmt"
"log"
"net/http"

"github.com/pkg/errors"
"github.com/senzing/git-action-slack-notification/configuration"
)

type Message struct {
Expand Down Expand Up @@ -42,13 +43,20 @@ func (message *Message) Send(webhook string) error {
return err
}
msgBytes := bytes.NewBuffer(msg)
response, err := http.Post(webhook, "application/json", msgBytes)

request, err := http.NewRequest(http.MethodPost, webhook, msgBytes)
if err != nil {
return err
}
request.Header.Set("Content-Type", "application/json")

response, err := http.DefaultClient.Do(request)
if err != nil {
return err
}

if response.StatusCode >= 299 {
err = errors.New(fmt.Sprintf("Exception: %s", response.Status))
err = fmt.Errorf(fmt.Sprintf("Exception: %s", response.Status))
}
fmt.Println(response.Status)

Expand All @@ -69,7 +77,7 @@ func main() {

slackMessage = new(Message)
slackMessage.Username = config.SlackUsername
slackMessage.IconURL = config.SlackIconUrl
slackMessage.IconURL = config.SlackIconURL
slackMessage.Channel = config.SlackChannel
slackMessage.Attachments = []Attachment{
{
Expand Down

0 comments on commit fef7e58

Please sign in to comment.