From db792158f2754090f00695e3a1a8eab4893f2353 Mon Sep 17 00:00:00 2001 From: Sam <109683132+kernelsam@users.noreply.github.com> Date: Wed, 21 Feb 2024 14:09:23 -0800 Subject: [PATCH] linting updates --- CODE_OF_CONDUCT.md | 2 +- README.md | 25 +++++++++++---------- docs/errors.md | 2 +- entrypoint.sh | 55 +++++++++++++++++++++++----------------------- 4 files changed, 43 insertions(+), 41 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index f6f9f91..0dc166a 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -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 diff --git a/README.md b/README.md index 10d22a4..2caeeaf 100644 --- a/README.md +++ b/README.md @@ -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 @@ -26,25 +26,26 @@ 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 @@ -80,7 +81,7 @@ 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! +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: @@ -96,7 +97,7 @@ 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` @@ -132,7 +133,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. @@ -158,8 +159,8 @@ 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' ``` @@ -168,6 +169,6 @@ jobs: 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) diff --git a/docs/errors.md b/docs/errors.md index 05c6801..715f296 100644 --- a/docs/errors.md +++ b/docs/errors.md @@ -1 +1 @@ -## Errors \ No newline at end of file +# Errors \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh index 66f31ac..effa927 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,4 +1,4 @@ -#!/bin/sh -l +#!/usr/bin/env bash PROJECT_URL="$INPUT_PROJECT" PROJECT1_URL="$INPUT_PROJECT1" @@ -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" @@ -135,6 +109,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:? required this environment variable}") if [ "$PROJECT_TYPE" = org ] || [ "$PROJECT_TYPE" = user ]; then