Skip to content

Commit

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

* linting updates

* add missed file

* update linting

* missing newline
  • Loading branch information
kernelsam authored Feb 22, 2024
1 parent ca6cfa2 commit 0c8b929
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 70 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
}
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 garage'
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 }}
35 changes: 18 additions & 17 deletions .github/workflows/build-docker-container.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
name: build-docker-container.yaml
on:
pull_request:
branches:
- main
workflow_dispatch:
name: docker build container

on: [push]

jobs:
buildDockerContainer:
name: Build Docker container
docker-build-container:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
- 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:
fetch-depth: '0'
- name: Print environment variables
run: printenv
- name: Git Merge With Main
run: git merge origin/main
- name: Build Docker container
run: make docker-build
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
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
34 changes: 19 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Overview

The repository holds and shows example usage of the github workflow that can automatically add issues and pull-requests to github projects. The workflow can check labels, project columns, and repository topics to conditionally add issues or pull-requests to selected projects.
The repository holds and shows example usage of the GitHub workflow that can automatically add issues and pull-requests to GitHub projects. The workflow can check labels, project columns, and repository topics to conditionally add issues or pull-requests to selected projects.

### Contents

Expand All @@ -26,25 +26,27 @@ The repository holds and shows example usage of the github workflow that can aut

## Inputs

#### `Projects`
### `Projects`

:thinking: The url of the project to be assigned to.
:thinking: The URL of the project to be assigned to.
You must use one of the follow sets of inputs:

- project
- project1 and/or project2

#### `Topics`

### `Topics`

:thinking: The string of the topics to check for. **Required** if you are using the project1 and/or project 2 inputs.

#### `Column_name`
### `Column_name`

**Optional**: The column name of the project, defaults to `'To do'` for issues and `'In progress'` for pull requests.

## Examples

### Repository project :pencil2:
### Repository project

:pencil2:

```yaml
name: Auto Assign to Project
Expand Down Expand Up @@ -79,11 +81,12 @@ jobs:
```
#### Notes
:thinking:
Be careful of using the conditions above (opened and labeled issues/PRs) because in such workflow, if the issue/PR is opened and labeled at the same time, it will be assigned to __both__ projects!
:thinking:
Be careful of using the conditions above (opened and labeled issues/PRs) because in such workflow, if the issue/PR is opened and labeled at the same time, it will be assigned to **both** projects!
You can use any combination of conditions. For example, to assign new issues or issues labeled with 'mylabel' to a project column, use:
```yaml
...

Expand All @@ -96,7 +99,8 @@ if: |
...
```

### Organization or User project
### Organization or User project

:pencil2:

Generate a token from the Organization settings or User Settings and add it as a secret in the repository secrets as `MY_GITHUB_TOKEN`
Expand Down Expand Up @@ -132,7 +136,7 @@ jobs:
column_name: 'Labeled'
```
### Using topics
### Using topics
:pencil2: Generate a token from the organization settings or User Settings and add it as a secret in the repository secrets as `MY_GITHUB_TOKEN`.
Under 'env:' add the "REPO_URL" variable and use the project1, project2, topic1, and topic2 inputs. If the repository has topic1 then it will be put in project1 and topic2 will be put in project2. If you are using the "column_name" input make sure that both projects have that column.
Expand All @@ -158,16 +162,16 @@ jobs:
uses: Senzing/github-action-add-issue-to-project@1.0.0
with:
project1: 'https://github.com/org/{org-name}/projects/2'
project1: 'https://github.com/org/{org-name}/projects/4'
topic1: 'my-topic1`
project2: 'https://github.com/org/{org-name}/projects/4'
topic1: 'my-topic1'
topic2: 'my-topic2'
column_name: 'Backlog'
```

## References

1. Github workflow
1. GitHub workflow
1. [Documentation](https://docs.github.com/en/rest/reference/actions)
1. [Github actions](https://github.com/features/actions)
1. [GitHub actions](https://github.com/features/actions)
1. Inspiration
1. [GitHub](https://github.com/srggrs/assign-one-project-github-action)
2 changes: 1 addition & 1 deletion docs/errors.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
## Errors
# Errors
57 changes: 30 additions & 27 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh -l
#!/usr/bin/env bash

PROJECT_URL="$INPUT_PROJECT"
PROJECT1_URL="$INPUT_PROJECT1"
Expand Down Expand Up @@ -61,32 +61,6 @@ get_project_type() {
unset _PROJECT_URL
}

if [ "$PROJECT1_URL" ]; then
_TOPICS=$(curl -s -X GET -u "$GITHUB_ACTOR:$TOKEN" --retry 3 \
-H "Accept: application/vnd.github.mercy-preview+json" \
${REPO_URL})

a=${_TOPICS#*topics}
b=${a#*[}
topics=${b%]*}

if echo "$topics" | grep -q "$TOPIC1"; then
PROJECT_URL=${PROJECT1_URL}

elif [echo "$topics" | grep -q "$TOPIC2"] && ["$PROJECT2_URL"]; then
PROJECT_URL=${PROJECT2_URL}

else
"This repository does not have a matching topic"
exit 1

fi
fi

curl \
-H "Accept: application/vnd.github.mercy-preview+json" \
https://api.github.com/

find_project_id() {
if [ "$PROJECT_URL" ]; then
_PROJECT_TYPE="$1"
Expand All @@ -95,10 +69,12 @@ find_project_id() {

case "$_PROJECT_TYPE" in
org)
# shellcheck disable=SC2001
_ORG_NAME=$(echo "$_PROJECT_URL" | sed -e 's@https://github.com/orgs/\([^/]\+\)/projects/[0-9]\+@\1@')
_ENDPOINT="https://api.github.com/orgs/$_ORG_NAME/projects"
;;
user)
# shellcheck disable=SC2001
_USER_NAME=$(echo "$_PROJECT_URL" | sed -e 's@https://github.com/users/\([^/]\+\)/projects/[0-9]\+@\1@')
_ENDPOINT="https://api.github.com/users/$_USER_NAME/projects"
;;
Expand Down Expand Up @@ -135,6 +111,33 @@ find_column_id() {
unset _PROJECT_ID _INITIAL_COLUMN_NAME _COLUMNS
}

if [ "$PROJECT1_URL" ]; then
_TOPICS=$(curl -s -X GET -u "$GITHUB_ACTOR:$TOKEN" --retry 3 \
-H "Accept: application/vnd.github.mercy-preview+json" \
"${REPO_URL}")

a=${_TOPICS#*topics}
b=${a#*[}
topics=${b%]*}

if echo "$topics" | grep -q "$TOPIC1"; then
PROJECT_URL=${PROJECT1_URL}

elif echo "$topics" | grep -q "$TOPIC2" && [ "$PROJECT2_URL" ] ; then
PROJECT_URL=${PROJECT2_URL}

else
"This repository does not have a matching topic"
exit 1

fi
fi

curl \
-H "Accept: application/vnd.github.mercy-preview+json" \
https://api.github.com/


PROJECT_TYPE=$(get_project_type "${PROJECT_URL:?<Error> required this environment variable}")

if [ "$PROJECT_TYPE" = org ] || [ "$PROJECT_TYPE" = user ]; then
Expand Down

0 comments on commit 0c8b929

Please sign in to comment.