[
  {
    "path": ".github/workflows/main.yml",
    "content": "# name: Auto Assign to Project(s)\n\n# on:\n#   issues:\n#     types: [opened, labeled]\n#   pull_request:\n#     types: [opened, labeled]\n# env:\n#   GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n\n# jobs:\n#   assign_one_project:\n#     runs-on: ubuntu-latest\n#     name: Assign to One Project\n#     steps:\n#     - name: Assign NEW issues and NEW pull requests to project 2\n#       uses: srggrs/assign-one-project-github-action@1.2.0\n#       if: github.event.action == 'opened'\n#       with:\n#         project: 'https://github.com/srggrs/assign-one-project-github-action/projects/2'\n\n#     - name: Assign issues and pull requests with `bug` label to project 3\n#       uses: srggrs/assign-one-project-github-action@1.2.0\n#       if: |\n#         contains(github.event.issue.labels.*.name, 'bug') ||\n#         contains(github.event.pull_request.labels.*.name, 'bug')\n#       with:\n#         project: 'https://github.com/srggrs/assign-one-project-github-action/projects/3'\n#         column_name: 'Labeled'\nname: Debug JSON\n\non:\n  issues:\n    types: [opened, labeled, unlabeled]\n  pull_request:\n    types: [opened, labeled, unlabeled]\nenv:\n  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n\njobs:\n  debugging:\n    runs-on: ubuntu-latest\n    name: Debugging\n    steps:\n    - name: Debugging JSON\n      run: |\n        echo \"Event Type: ${{ github.event_name }}\"\n        env\n        cat $GITHUB_EVENT_PATH\n"
  },
  {
    "path": ".gitignore",
    "content": "*.sublime*\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "# Change Log\n\n\nAll notable changes to this project will be documented in this file.\n\nThe format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), with an added `List of PRs` section and links to the relevant PRs on the individal updates. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n\n## [Unreleased](https://github.com/srggrs/assign-one-project-github-action/compare/master...HEAD)\n\n#### Added\n\nTBC\n\n#### Changed\n\nTBC\n\n#### Fixed\n\nTBC\n\n#### Removed\n\nTBC\n\n## [1.3.1](https://github.com/srggrs/assign-one-project-github-action/compare/1.3.1...HEAD) (2021-10-04)\n\n#### Added\n\n* Added `issue_comment` as trigger [#76](https://github.com/srggrs/assign-one-project-github-action/pull/76).\n\n#### Fixed\n\n* Better error messages [#1dbdca2](https://github.com/srggrs/assign-one-project-github-action/commit/1dbdca2)\n\n## [1.3.0](https://github.com/srggrs/assign-one-project-github-action/compare/1.3.0...HEAD) (2021-09-26)\n\n#### Added\n* Added pagination in project finding [#69](https://github.com/srggrs/assign-one-project-github-action/pull/69).\n\n#### Fixed\n* Change documentation: `event` to `event_name` [#75](https://github.com/srggrs/assign-one-project-github-action/pull/75).\n\n\n## [1.2.1](https://github.com/srggrs/assign-one-project-github-action/compare/prep-release-1.2.1...HEAD) (2021-03-07)\n\n#### Added\n* Added support for repository forks with `pull request target` event [#62](https://github.com/srggrs/assign-one-project-github-action/pull/62).\n* Added Changelog [#66](https://github.com/srggrs/assign-one-project-github-action/pull/66).\n* Added Code of Conduct [#66](https://github.com/srggrs/assign-one-project-github-action/pull/66).\n\n#### Changed\n\n* Changed README with latest changes [#66](https://github.com/srggrs/assign-one-project-github-action/pull/66).\n* Change action to use local Docker image [#68](https://github.com/srggrs/assign-one-project-github-action/pull/68).\n\n## [1.2.0](https://github.com/srggrs/assign-one-project-github-action/compare/prep-release-1.2.0...HEAD) ()\n\nLast release to start tracking changes.\n\nFeatures:\n* add issue or PR to a project column\n* specify the name of the column [#35](https://github.com/srggrs/assign-one-project-github-action/pull/35)\n\n#### List of PRs\n\n- [#68](https://github.com/srggrs/assign-one-project-github-action/pull/68) fix: change action to use local dockerfile.\n- [#66](https://github.com/srggrs/assign-one-project-github-action/pull/66) doc: added Changelog and code of conduct, change readme.\n- [#62](https://github.com/srggrs/assign-one-project-github-action/pull/62) feat: added support for Pull request target for forks of repository.\n- [#59](https://github.com/srggrs/assign-one-project-github-action/pull/59) doc: fix typo.\n- [#35](https://github.com/srggrs/assign-one-project-github-action/pull/35) feat: add support for custom column name.\n"
  },
  {
    "path": "CODE_OF_CONDUCT.md",
    "content": "<!-- copied from https://github.com/scikit-learn/scikit-learn/blob/master/CODE_OF_CONDUCT.md -->\n# Code Of Conduct\n\nThis project is for a community based on openness, as well as friendly and didactic discussions.\n\nSuch community should aspire to treat everybody equally, and value their contributions.\n\nDecisions are made based on technical merit and consensus.\n\nCode is not the only way to help the project. Reviewing pull requests, answering questions to help others on mailing lists or issues, organizing and teaching tutorials, working on the website, improving the documentation, are all priceless contributions.\n\nSuch community should abide by the principles of openness, respect, and consideration of others of the Python Software Foundation: https://www.python.org/psf/codeofconduct/\n\n## Extra Guidelines\nPlease follow these guidelines in all your interactions:\n\n- __Behave professionally__. Harassment and sexist, racist, or exclusionary comments or jokes are not appropriate. Harassment includes sustained disruption of talks or other events, inappropriate physical contact, sexual attention or innuendo, deliberate intimidation, stalking, and photography or recording of an individual without consent. It also includes offensive comments related to gender, sexual orientation, disability, physical appearance, body size, race or religion.\n- __All communication should be appropriate__ for a professional audience including people of many different backgrounds. Sexual language and imagery is not appropriate.\n- __Be kind to others__. Do not insult or put down other GitHub users.\n- Participants asked to stop any inappropriate behaviour are expected to comply immediately. People violating these rules may be blocked at the discretion of the mantainers.\n"
  },
  {
    "path": "Dockerfile",
    "content": "# Container image that runs your code\nFROM alpine:3.10\n\nRUN apk add --no-cache --no-progress curl jq\n\n# Copies your code file from your action repository to the filesystem path `/` of the container\nCOPY entrypoint.sh /entrypoint.sh\n# Code file to execute when the docker container starts up (`entrypoint.sh`)\nENTRYPOINT [\"/entrypoint.sh\"]\n"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2019 Sergio Pintaldi\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# GitHub Action for Assign to One Project\n\n[![Docker Cloud Automated build](https://img.shields.io/docker/cloud/automated/srggrs/assign-one-project-github-action)][docker]\n[![Docker Cloud Build Status](https://img.shields.io/docker/cloud/build/srggrs/assign-one-project-github-action)][docker]\n[![Docker Pulls](https://img.shields.io/docker/pulls/srggrs/assign-one-project-github-action)][docker]\n[![GitHub license](https://img.shields.io/github/license/srggrs/assign-one-project-github-action.svg)][license]\n![Latest Version](https://img.shields.io/github/v/release/srggrs/assign-one-project-github-action?color=orange&label=latest%20release)\n\n[docker]: https://hub.docker.com/r/srggrs/assign-one-project-github-action\n[license]: https://github.com/srggrs/assign-one-project-github-action/blob/master/LICENSE\n\nAutomatically add an issue or pull request to specific [GitHub Project](https://help.github.com/articles/about-project-boards/) when you __create__ and/or __label__ them. By default, the issues are assigned to the __`To do`__ column and the pull requests to the __`In progress`__ one, so make sure you have those columns in your project dashboard. But the workflow __allowed you to specify the column name as input__, so you can assign the issues/PRs based on a set of conditions to a specific column of a specific project.\n\n## Latest features:\n\n* included `issue_comment` as trigger for this action.\n* added project pagination for searching 100+ GitHub projects.\n\n## Acknowledgment & Motivations\n\nThis action has been modified from the original action from [masutaka](https://github.com/masutaka/github-actions-all-in-one-project). I needed to fix it as the original docker container would not build. Also I think the GitHub Action syntax changed a bit.\n\nI would like to thank @SunRunAway for adding the labelling functionality and custom column input.\n\n## Inputs\n\n### `project`\n\n**Required** The url of the project to be assigned to.\n\n### `column_name`\n\nThe column name of the project, defaults to `'To do'` for issues and `'In progress'` for pull requests.\n\n## Example usage\n\nExamples of action:\n\n### Repository project\n\n```yaml\nname: Auto Assign to Project(s)\n\non:\n  issues:\n    types: [opened, labeled]\n  pull_request:\n    types: [opened, labeled]\n  issue_comment:\n    types: [created]\nenv:\n  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n\njobs:\n  assign_one_project:\n    runs-on: ubuntu-latest\n    name: Assign to One Project\n    steps:\n    - name: Assign NEW issues and NEW pull requests to project 2\n      uses: srggrs/assign-one-project-github-action@1.2.1\n      if: github.event.action == 'opened'\n      with:\n        project: 'https://github.com/srggrs/assign-one-project-github-action/projects/2'\n\n    - name: Assign issues and pull requests with `bug` label to project 3\n      uses: srggrs/assign-one-project-github-action@1.2.1\n      if: |\n        contains(github.event.issue.labels.*.name, 'bug') ||\n        contains(github.event.pull_request.labels.*.name, 'bug')\n      with:\n        project: 'https://github.com/srggrs/assign-one-project-github-action/projects/3'\n        column_name: 'Labeled'\n```\n\n#### __Notes__\nBe 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!\n\n\nYou can use any combination of conditions. For example, to assign new issues or issues labeled with 'mylabel' to a project column, use:\n```yaml\n...\n\nif: |\n  github.event_name == 'issues' &&\n  (\n    github.event.action == 'opened' ||\n    contains(github.event.issue.labels.*.name, 'mylabel')\n  )\n...\n```\n\n### Organisation or User project\n\nGenerate a token from the Organisation settings or User Settings and add it as a secret in the repository secrets as `MY_GITHUB_TOKEN`\n\n```yaml\nname: Auto Assign to Project(s)\n\non:\n  issues:\n    types: [opened, labeled]\n  pull_request_target:\n    types: [opened, labeled]\n  issue_comment:\n    types: [created]\nenv:\n  MY_GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}\n\njobs:\n  assign_one_project:\n    runs-on: ubuntu-latest\n    name: Assign to One Project\n    steps:\n    - name: Assign NEW issues and NEW pull requests to project 2\n      uses: srggrs/assign-one-project-github-action@1.2.1\n      if: github.event.action == 'opened'\n      with:\n        project: 'https://github.com/srggrs/assign-one-project-github-action/projects/2'\n\n    - name: Assign issues and pull requests with `bug` label to project 3\n      uses: srggrs/assign-one-project-github-action@1.2.1\n      if: |\n        contains(github.event.issue.labels.*.name, 'bug') ||\n        contains(github.event.pull_request.labels.*.name, 'bug')\n      with:\n        project: 'https://github.com/srggrs/assign-one-project-github-action/projects/3'\n        column_name: 'Labeled'\n```\n\n## [Change Log](./CHANGELOG.md)\n\nPlease refer to the list of changes [here](./CHANGELOG.md)\n"
  },
  {
    "path": "action.yml",
    "content": "# action.yml\nname: 'Assign to One Project'\ndescription: 'Assign new/labeled Issue or Pull Request to a specific project dashboard column'\nauthor: srggrs\ninputs:\n  project:\n    description: 'The url of the project to be assigned to.'\n    required: true\n  column_name:\n    description: 'The column name of the project, defaults to \"To do\" for issues and \"In progress\" for pull requests.'\n    required: false\n\nruns:\n  using: 'docker'\n  image: 'Dockerfile'\n  args:\n    - ${{ inputs.project }}\n    - ${{ inputs.column_name }}\n\nbranding:\n  icon: 'box'\n  color: 'red'\n"
  },
  {
    "path": "entrypoint.sh",
    "content": "#!/bin/sh -l\n\nPROJECT_URL=\"$INPUT_PROJECT\"\nif [ -z \"$PROJECT_URL\" ]; then\n  echo \"Project input variable is not defined.\" >&2\n  exit 1\nfi\n\nget_project_type() {\n  _PROJECT_URL=\"$1\"\n\n  case \"$_PROJECT_URL\" in\n    https://github.com/orgs/*)\n      echo \"org\"\n      ;;\n    https://github.com/users/*)\n      echo \"user\"\n      ;;\n    https://github.com/*/projects/*)\n      echo \"repo\"\n      ;;\n    *)\n      echo \"Invalid Project URL: '$_PROJECT_URL' . Please pass a valid Project URL in the project input variable\" >&2\n      exit 1\n      ;;\n  esac\n\n  unset _PROJECT_URL\n}\n\nget_next_url_from_headers() {\n  _HEADERS_FILE=$1\n  grep -i '^link' \"$_HEADERS_FILE\" | tr ',' '\\n'| grep \\\"next\\\" | sed 's/.*<\\(.*\\)>.*/\\1/'\n}\n\nfind_project_id() {\n  _PROJECT_TYPE=\"$1\"\n  _PROJECT_URL=\"$2\"\n\n  case \"$_PROJECT_TYPE\" in\n    org)\n      _ORG_NAME=$(echo \"$_PROJECT_URL\" | sed -e 's@https://github.com/orgs/\\([^/]\\+\\)/projects/[0-9]\\+@\\1@')\n      _ENDPOINT=\"https://api.github.com/orgs/$_ORG_NAME/projects?per_page=100\"\n      ;;\n    user)\n      _USER_NAME=$(echo \"$_PROJECT_URL\" | sed -e 's@https://github.com/users/\\([^/]\\+\\)/projects/[0-9]\\+@\\1@')\n      _ENDPOINT=\"https://api.github.com/users/$_USER_NAME/projects?per_page=100\"\n      ;;\n    repo)\n      _ENDPOINT=\"https://api.github.com/repos/$GITHUB_REPOSITORY/projects?per_page=100\"\n      ;;\n  esac\n  \n  _NEXT_URL=\"$_ENDPOINT\"\n\n  while : ; do\n\n    _PROJECTS=$(curl -s -X GET -u \"$GITHUB_ACTOR:$TOKEN\" --retry 3 \\\n            -H 'Accept: application/vnd.github.inertia-preview+json' \\\n            -D /tmp/headers \\\n            \"$_NEXT_URL\")\n\n    _PROJECTID=$(echo \"$_PROJECTS\" | jq -r \".[] | select(.html_url == \\\"$_PROJECT_URL\\\").id\")\n    _NEXT_URL=$(get_next_url_from_headers '/tmp/headers')\n\n    if [ \"$_PROJECTID\" != \"\" ]; then\n      echo \"$_PROJECTID\"\n    elif [ \"$_NEXT_URL\" == \"\" ]; then\n      echo \"No project was found.\" >&2\n      exit 1\n    fi\n  done\n\n  unset _PROJECT_TYPE _PROJECT_URL _ORG_NAME _USER_NAME _ENDPOINT _PROJECTS _PROJECTID _NEXT_URL\n}\n\nfind_column_id() {\n  _PROJECT_ID=\"$1\"\n  _INITIAL_COLUMN_NAME=\"$2\"\n\n  _COLUMNS=$(curl -s -X GET -u \"$GITHUB_ACTOR:$TOKEN\" --retry 3 \\\n          -H 'Accept: application/vnd.github.inertia-preview+json' \\\n          \"https://api.github.com/projects/$_PROJECT_ID/columns\")\n\n\n  echo \"$_COLUMNS\" | jq -r \".[] | select(.name == \\\"$_INITIAL_COLUMN_NAME\\\").id\"\n  unset _PROJECT_ID _INITIAL_COLUMN_NAME _COLUMNS\n}\n\nPROJECT_TYPE=$(get_project_type \"${PROJECT_URL:?<Error> required this environment variable}\")\n\nif [ \"$PROJECT_TYPE\" = org ] || [ \"$PROJECT_TYPE\" = user ]; then\n  if [ -z \"$MY_GITHUB_TOKEN\" ]; then\n    echo \"MY_GITHUB_TOKEN not defined\" >&2\n    exit 1\n  fi\n\n  TOKEN=\"$MY_GITHUB_TOKEN\" # It's User's personal access token. It should be secret.\nelse\n  if [ -z \"$GITHUB_TOKEN\" ]; then\n    echo \"GITHUB_TOKEN not defined\" >&2\n    exit 1\n  fi\n\n  TOKEN=\"$GITHUB_TOKEN\"    # GitHub sets. The scope in only the repository containing the workflow file.\nfi\n\nINITIAL_COLUMN_NAME=\"$INPUT_COLUMN_NAME\"\nif [ -z \"$INITIAL_COLUMN_NAME\" ]; then\n  # assing the column name by default\n  INITIAL_COLUMN_NAME='To do'\n  if [ \"$GITHUB_EVENT_NAME\" == \"pull_request\" ] || [ \"$GITHUB_EVENT_NAME\" == \"pull_request_target\" ]; then\n    echo \"changing column name for PR event\"\n    INITIAL_COLUMN_NAME='In progress'\n  fi\nfi\n\n\nPROJECT_ID=$(find_project_id \"$PROJECT_TYPE\" \"$PROJECT_URL\")\nINITIAL_COLUMN_ID=$(find_column_id \"$PROJECT_ID\" \"${INITIAL_COLUMN_NAME:?<Error> required this environment variable}\")\n\nif [ -z \"$INITIAL_COLUMN_ID\" ]; then\n  echo \"Column name '$INITIAL_COLUMN_ID' is not found.\" >&2\n  exit 1\nfi\n\ncase \"$GITHUB_EVENT_NAME\" in\n  issues|issue_comment)\n    ISSUE_ID=$(jq -r '.issue.id' < \"$GITHUB_EVENT_PATH\")\n\n    # Add this issue to the project column\n    curl -s -X POST -u \"$GITHUB_ACTOR:$TOKEN\" --retry 3 \\\n     -H 'Accept: application/vnd.github.inertia-preview+json' \\\n     -d \"{\\\"content_type\\\": \\\"Issue\\\", \\\"content_id\\\": $ISSUE_ID}\" \\\n     \"https://api.github.com/projects/columns/$INITIAL_COLUMN_ID/cards\"\n    ;;\n  pull_request|pull_request_target)\n    PULL_REQUEST_ID=$(jq -r '.pull_request.id' < \"$GITHUB_EVENT_PATH\")\n\n    # Add this pull_request to the project column\n    curl -s -X POST -u \"$GITHUB_ACTOR:$TOKEN\" --retry 3 \\\n     -H 'Accept: application/vnd.github.inertia-preview+json' \\\n     -d \"{\\\"content_type\\\": \\\"PullRequest\\\", \\\"content_id\\\": $PULL_REQUEST_ID}\" \\\n     \"https://api.github.com/projects/columns/$INITIAL_COLUMN_ID/cards\"\n    ;;\n  *)\n    echo \"Nothing to be done on this action: '$GITHUB_EVENT_NAME'\" >&2\n    exit 1\n    ;;\nesac\n"
  }
]