From a252e4f61b251d02fc42681766cb0e73df16b64f Mon Sep 17 00:00:00 2001
From: chyccs <chyccs@naver.com>
Date: Wed, 29 Mar 2023 13:39:46 +0900
Subject: [PATCH] misc: initial commit (#1)

---
 .github/auto_assign.yml              |  29 ++++++
 .github/dependabot.yml               |  19 ++++
 .github/labeler.yml                  |   9 ++
 .github/pull_request_template.md     |  21 +++++
 .github/workflows/example-action.yml |  36 ++++++++
 .gitignore                           |   2 +
 CODE_OF_CONDUCT.md                   | 128 +++++++++++++++++++++++++++
 LICENSE                              |  24 +++++
 README.md                            |  65 ++++++++++++++
 action.yaml                          |  63 +++++++++++++
 src/pull-request.sh                  |  62 +++++++++++++
 11 files changed, 458 insertions(+)
 create mode 100644 .github/auto_assign.yml
 create mode 100644 .github/dependabot.yml
 create mode 100644 .github/labeler.yml
 create mode 100644 .github/pull_request_template.md
 create mode 100644 .github/workflows/example-action.yml
 create mode 100644 .gitignore
 create mode 100644 CODE_OF_CONDUCT.md
 create mode 100644 LICENSE
 create mode 100644 README.md
 create mode 100644 action.yaml
 create mode 100755 src/pull-request.sh

diff --git a/.github/auto_assign.yml b/.github/auto_assign.yml
new file mode 100644
index 0000000..3204725
--- /dev/null
+++ b/.github/auto_assign.yml
@@ -0,0 +1,29 @@
+# Set to true to add reviewers to pull requests
+addReviewers: false
+
+# Set to true to add assignees to pull requests
+addAssignees: author
+
+# A list of team reviewers to be added to pull requests (GitHub team slug)
+# reviewers:
+#   -
+
+# Number of reviewers has no impact on Github teams
+# Set 0 to add all the reviewers (default: 0)
+numberOfReviewers: 0
+
+# A list of assignees, overrides reviewers if set
+# assignees:
+#   - assigneeA
+
+# A number of assignees to add to the pull request
+# Set to 0 to add all of the assignees.
+# Uses numberOfReviewers if unset.
+# numberOfAssignees: 2
+
+# A list of keywords to be skipped the process that add reviewers if pull requests include it
+# skipKeywords:
+#   - wip
+
+# Set to true to enable it to run on draft pull requests
+runOnDraft: true
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 0000000..38c5ec7
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,19 @@
+# To get started with Dependabot version updates, you'll need to specify which
+# package ecosystems to update and where the package manifests are located.
+# Please see the documentation for all configuration options:
+# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
+
+version: 2
+updates:
+  - package-ecosystem: "pip" # See documentation for possible values
+    directory: "/" # Location of package manifests
+    rebase-strategy: "auto"
+    assignees:
+      - "chyccs"
+    reviewers:
+      - "chyccs"
+    schedule:
+      interval: "daily"
+#      day: "wednesday"
+      time: "09:00"
+      timezone: "Asia/Seoul"
diff --git a/.github/labeler.yml b/.github/labeler.yml
new file mode 100644
index 0000000..b46d65f
--- /dev/null
+++ b/.github/labeler.yml
@@ -0,0 +1,9 @@
+workflows:
+- .github/workflows/*
+
+test:
+- test_*.py
+
+pipfile:
+- Pipfile
+- Pipfile.lock
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md
new file mode 100644
index 0000000..bad2cff
--- /dev/null
+++ b/.github/pull_request_template.md
@@ -0,0 +1,21 @@
+- Major Reviewer:
+
+## Background
+
+<!--- Why is this change required? What problem does it solve? -->
+<!--- If it fixes an open issue, please link to the issue here. -->
+
+## Summary
+
+<!--- Provide a summary of your changes. -->
+<!--- It's a good idea to include the issue you are trying to solve and how to fix it. -->
+
+## Checklist
+
+- [ ] Backward compatible?
+- [ ] Test enough in your local environment?
+- [ ] Add related test cases?
+
+## Remind
+
+- Merge strategies(`Create a merge commit` vs `Squash and merge`)
diff --git a/.github/workflows/example-action.yml b/.github/workflows/example-action.yml
new file mode 100644
index 0000000..d8546df
--- /dev/null
+++ b/.github/workflows/example-action.yml
@@ -0,0 +1,36 @@
+name: Example Action
+
+on:
+  issue_comment:
+    types: [created]
+  issues:
+    types: [opened, edited]
+  
+permissions:
+  contents: write
+  issues: write
+  pull-requests: write
+
+jobs:
+  create-pr:
+    runs-on: ubuntu-latest
+    if: ${{ !github.event.issue.pull_request }}
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v2
+
+      - name: Create PR when issue_comment event occured
+        if: ${{ startsWith(github.event.comment.body, '@pr ') }}
+        uses: ./ # Uses an action in the root directory
+        # or use a released GitHub Action
+        #uses: chyccs/pull-request-typography@master
+        with:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+
+      - name: Create PR when issues was created
+        if: ${{ !github.event.comment.body }}
+        uses: ./ # Uses an action in the root directory
+        # or use a released GitHub Action
+        #uses: chyccs/pull-request-typography@master
+        with:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..43d3056
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+.DS_Store
+hwr_analyzer
diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md
new file mode 100644
index 0000000..18c9147
--- /dev/null
+++ b/CODE_OF_CONDUCT.md
@@ -0,0 +1,128 @@
+# Contributor Covenant Code of Conduct
+
+## Our Pledge
+
+We as members, contributors, and leaders pledge to make participation in our
+community a harassment-free experience for everyone, regardless of age, body
+size, visible or invisible disability, ethnicity, sex characteristics, gender
+identity and expression, level of experience, education, socio-economic status,
+nationality, personal appearance, race, religion, or sexual identity
+and orientation.
+
+We pledge to act and interact in ways that contribute to an open, welcoming,
+diverse, inclusive, and healthy community.
+
+## Our Standards
+
+Examples of behavior that contributes to a positive environment for our
+community include:
+
+* Demonstrating empathy and kindness toward other people
+* Being respectful of differing opinions, viewpoints, and experiences
+* Giving and gracefully accepting constructive feedback
+* Accepting responsibility and apologizing to those affected by our mistakes,
+  and learning from the experience
+* Focusing on what is best not just for us as individuals, but for the
+  overall community
+
+Examples of unacceptable behavior include:
+
+* The use of sexualized language or imagery, and sexual attention or
+  advances of any kind
+* Trolling, insulting or derogatory comments, and personal or political attacks
+* Public or private harassment
+* Publishing others' private information, such as a physical or email
+  address, without their explicit permission
+* Other conduct which could reasonably be considered inappropriate in a
+  professional setting
+
+## Enforcement Responsibilities
+
+Community leaders are responsible for clarifying and enforcing our standards of
+acceptable behavior and will take appropriate and fair corrective action in
+response to any behavior that they deem inappropriate, threatening, offensive,
+or harmful.
+
+Community leaders have the right and responsibility to remove, edit, or reject
+comments, commits, code, wiki edits, issues, and other contributions that are
+not aligned to this Code of Conduct, and will communicate reasons for moderation
+decisions when appropriate.
+
+## Scope
+
+This Code of Conduct applies within all community spaces, and also applies when
+an individual is officially representing the community in public spaces.
+Examples of representing our community include using an official e-mail address,
+posting via an official social media account, or acting as an appointed
+representative at an online or offline event.
+
+## Enforcement
+
+Instances of abusive, harassing, or otherwise unacceptable behavior may be
+reported to the community leaders responsible for enforcement at
+.
+All complaints will be reviewed and investigated promptly and fairly.
+
+All community leaders are obligated to respect the privacy and security of the
+reporter of any incident.
+
+## Enforcement Guidelines
+
+Community leaders will follow these Community Impact Guidelines in determining
+the consequences for any action they deem in violation of this Code of Conduct:
+
+### 1. Correction
+
+**Community Impact**: Use of inappropriate language or other behavior deemed
+unprofessional or unwelcome in the community.
+
+**Consequence**: A private, written warning from community leaders, providing
+clarity around the nature of the violation and an explanation of why the
+behavior was inappropriate. A public apology may be requested.
+
+### 2. Warning
+
+**Community Impact**: A violation through a single incident or series
+of actions.
+
+**Consequence**: A warning with consequences for continued behavior. No
+interaction with the people involved, including unsolicited interaction with
+those enforcing the Code of Conduct, for a specified period of time. This
+includes avoiding interactions in community spaces as well as external channels
+like social media. Violating these terms may lead to a temporary or
+permanent ban.
+
+### 3. Temporary Ban
+
+**Community Impact**: A serious violation of community standards, including
+sustained inappropriate behavior.
+
+**Consequence**: A temporary ban from any sort of interaction or public
+communication with the community for a specified period of time. No public or
+private interaction with the people involved, including unsolicited interaction
+with those enforcing the Code of Conduct, is allowed during this period.
+Violating these terms may lead to a permanent ban.
+
+### 4. Permanent Ban
+
+**Community Impact**: Demonstrating a pattern of violation of community
+standards, including sustained inappropriate behavior,  harassment of an
+individual, or aggression toward or disparagement of classes of individuals.
+
+**Consequence**: A permanent ban from any sort of public interaction within
+the community.
+
+## Attribution
+
+This Code of Conduct is adapted from the [Contributor Covenant][homepage],
+version 2.0, available at
+https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
+
+Community Impact Guidelines were inspired by [Mozilla's code of conduct
+enforcement ladder](https://github.com/mozilla/diversity).
+
+[homepage]: https://www.contributor-covenant.org
+
+For answers to common questions about this code of conduct, see the FAQ at
+https://www.contributor-covenant.org/faq. Translations are available at
+https://www.contributor-covenant.org/translations.
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..fdddb29
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,24 @@
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+For more information, please refer to <https://unlicense.org>
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..8d8c9cc
--- /dev/null
+++ b/README.md
@@ -0,0 +1,65 @@
+# Empty Pull-Request Actions
+
+### Background
+Before starting work on a reported issue, a `pull-request` can be created arbitrarily by using the `--allow-empty` option of the `git commit` command.
+
+### Usage
+* Use `issue_comment` event trigger
+
+```yaml
+on:
+  issue_comment:
+    types: [created]
+  
+permissions:
+  contents: write
+  issues: write
+  pull-requests: write
+
+jobs:
+  create-pr:
+    runs-on: ubuntu-latest
+    if: ${{ !github.event.issue.pull_request }}
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v2
+
+      - name: Create PR when issue_comment event occured
+        if: ${{ startsWith(github.event.comment.body, '@pr ') }}
+        uses: chyccs/empty-pr-actions@master
+        with:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+```
+
+* Use `issues` event trigger
+
+```yaml
+on:
+  issues:
+    types: [opened, edited]
+  
+permissions:
+  contents: write
+  issues: write
+  pull-requests: write
+
+jobs:
+  create-pr:
+    runs-on: ubuntu-latest
+    if: ${{ !github.event.issue.pull_request }}
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v2
+
+      - name: Create PR when issues was created
+        uses: chyccs/empty-pr-actions@master
+        with:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+```
+
+<!-- | Param | Desc | Type | Required |
+| -- | -- | -- | -- |
+| GITHUB_TOKEN | [Token explain](#token) | string | ✖ |
+| pull_request_name | The number of issue. When not input, it will be obtained from the trigger event | number | ✖ |
+| assignees | Designated person. No operation when no input or empty character | string | ✖ |
+| random-to | When set, it will be randomly selected in assignees | number | ✖ | -->
diff --git a/action.yaml b/action.yaml
new file mode 100644
index 0000000..9f1ca5f
--- /dev/null
+++ b/action.yaml
@@ -0,0 +1,63 @@
+name: 'Empty PR Actions'
+
+description: 'GitHub Actions that automatically creates an empty pull request linked to an issue'
+
+branding:
+  icon: 'git-pull-request'
+  color: 'black'
+
+inputs:
+  assignee:
+    description: 'assignee'
+    required: false
+    default: ${{ github.event.issue.assignee.name }}
+
+  email:
+    description: 'email'
+    required: false
+    default: ${{ github.event.issue.assignee.email }}
+  
+  login:
+    description: 'login of assignee'
+    required: false
+    default: ${{ github.event.issue.assignee.login }}
+
+  GITHUB_TOKEN:
+    description: 'Github Token'
+    required: true
+
+runs:
+  using: 'composite'
+  steps:
+    - name: Move to path of action
+      run: |
+        cd ${{ github.action_path }}
+        pwd="$(pwd)"
+        echo "local_action_path=$pwd" >> $GITHUB_ENV
+      shell: bash
+
+    - id: cache-cargo
+      uses: actions/cache@v3
+      with:
+        path: ~/.cargo/bin/
+        key: ${{ runner.os }}-cargo
+
+    - name: Install dependencies
+      if: steps.cache-cargo.outputs.cache-hit != 'true'
+      run: |
+        cd ${{ github.action_path }}
+        cargo install ccase
+      shell: bash
+    
+    - name: run
+      shell: bash
+      run: |
+        cd ${{ github.action_path }}
+        chmod +x "./src/pull-request.sh"
+        ./src/pull-request.sh -n $number -o $owner -e $email -i "${{ github.event.issue.title }}" -r $GITHUB_REPOSITORY -l $login
+      env:
+        number: ${{ github.event.issue.number }}
+        owner: ${{ inputs.assignee }}
+        email: ${{ inputs.email }}
+        login: ${{ inputs.login }}
+        GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
diff --git a/src/pull-request.sh b/src/pull-request.sh
new file mode 100755
index 0000000..f6ae483
--- /dev/null
+++ b/src/pull-request.sh
@@ -0,0 +1,62 @@
+#! /bin/bash
+
+while getopts b:h:n:p:i:o:e:l:r: flag
+do
+    case "${flag}" in
+        b) base_branch=${OPTARG};;
+        h) head_branch=${OPTARG};;
+        n) number=${OPTARG};;
+        p) pull_request_title=${OPTARG};;
+        i) issue_title=${OPTARG};;
+        o) owner=${OPTARG};;
+        e) email=${OPTARG};;
+        l) login=${OPTARG};;
+        r) repo=${OPTARG};;
+    esac
+done
+
+if [ -z $head_branch ]
+then
+    issue_title_converted=$(echo "$issue_title" | sed 's/\([^a-zA-Z0-9]\)/ /g' )
+    head_branch="$number-$(~/.cargo/bin/ccase -b ' ' -t kebab "$issue_title_converted" | ~/.cargo/bin/ccase -f pascal -t kebab)"
+fi
+
+if [ -z $pull_request_title ]
+then
+    issue_title_converted="$(~/.cargo/bin/ccase -f pascal -t kebab "$issue_title")"
+    tag=$(echo "$issue_title_converted" | sed 's/\(.*\)\:\(.*\)/\1/g')
+    contents=$(echo "$issue_title_converted" | sed 's/\(.*\)\:\(.*\)/\2/g')
+    pull_request_title=$(echo "$tag: #$number $contents")
+fi
+
+echo "::debug::head_branch=$head_branch"
+echo "::debug::pull_request_title=$pull_request_title"
+
+gh issue develop -c "$number" --name "$head_branch" --base "$base_branch" --repo "$repo"
+result=$?
+echo "::debug::gh issue develop -c $number --name "$head_branch" --base $base_branch --repo $repo => $result"
+
+if [ $result -eq 0 ]
+then
+    git config --local user.email "$email"
+    git config --local user.name "$owner"
+    git commit --allow-empty -m "trigger notification\n[skip ci]"
+    
+    git push --set-upstream origin "$head_branch"
+    echo "::debug::git push --set-upstream origin $head_branch"
+    
+    # if [ -z $login ]
+    # then
+    #     assignee=$(echo " -a $login")
+    # else  
+    #     assignee=""
+    # fi
+
+    new_pr=$(gh pr create --title "$pull_request_title" --repo "$repo" --base "$base_branch" --head "$head_branch" --body-file ".github/pull_request_template.md")
+    echo "::debug::gh pr create --title $pull_request_title --body ' ' --repo $repo --base $base_branch --head $head_branch --body-file '.github/pull_request_template.md'"
+
+    gh issue comment $number --body "Pull Request created. $new_pr" --repo $repo
+else
+    echo "::debug::branch is already created"
+    gh issue comment $number --body "Can not create Pull Request. Branch is already exists" --repo $repo
+fi