mirror of
https://github.com/actions/add-to-project.git
synced 2025-12-10 12:07:05 +00:00
Compare commits
176 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
960fbad431 | ||
|
|
a130af5794 | ||
|
|
8d2064c2fe | ||
|
|
cd062f6530 | ||
|
|
c7ca843e95 | ||
|
|
c30dddf387 | ||
|
|
9eaa8568e2 | ||
|
|
195ebe73dd | ||
|
|
8f9378c977 | ||
|
|
edd3921f6c | ||
|
|
73dbef5228 | ||
|
|
b749f03d83 | ||
|
|
f1318f907d | ||
|
|
58045a0196 | ||
|
|
b79a170093 | ||
|
|
7a1b708e24 | ||
|
|
7e0e2c594b | ||
|
|
5a722b2d85 | ||
|
|
b84343956f | ||
|
|
fde71205f0 | ||
|
|
0639048d29 | ||
|
|
889cb383ac | ||
|
|
394bc02c66 | ||
|
|
e72a91f059 | ||
|
|
d37ee53182 | ||
|
|
b132be1646 | ||
|
|
ae3d163bf0 | ||
|
|
c6c527b7d4 | ||
|
|
17681e1444 | ||
|
|
5ee4c2c94a | ||
|
|
d3d1191194 | ||
|
|
5e951ed275 | ||
|
|
d8fd9122ff | ||
|
|
8afc027fc3 | ||
|
|
d3b6ae9953 | ||
|
|
327b1a6a80 | ||
|
|
51e172a520 | ||
|
|
2c51ab2882 | ||
|
|
283800435b | ||
|
|
bb4087f96d | ||
|
|
d5bf1a4311 | ||
|
|
7ecd3b9a8a | ||
|
|
019149543c | ||
|
|
82f0eaddf3 | ||
|
|
11ec699375 | ||
|
|
d79571d873 | ||
|
|
6979245da4 | ||
|
|
1450adf89b | ||
|
|
686e886c25 | ||
|
|
4cdd6f143b | ||
|
|
24a59b80ce | ||
|
|
eca008a168 | ||
|
|
dd6c3f1c1c | ||
|
|
338ac1805e | ||
|
|
2ecb35a6bd | ||
|
|
8ff00cfda3 | ||
|
|
dfe9c0bd14 | ||
|
|
0decb7a26e | ||
|
|
96ce2f0192 | ||
|
|
b572ef66d4 | ||
|
|
dbdd6bcdc8 | ||
|
|
8a130a1de7 | ||
|
|
b6d4389ed6 | ||
|
|
f5e0362b57 | ||
|
|
836536efd8 | ||
|
|
6133899d5e | ||
|
|
35a1c9762b | ||
|
|
8a044413b5 | ||
|
|
8bdfd1c79c | ||
|
|
1ec83d22e4 | ||
|
|
f82d1e43cf | ||
|
|
e83fe43a76 | ||
|
|
7048934db4 | ||
|
|
9b06c490c1 | ||
|
|
90e8168771 | ||
|
|
e7bfcd815f | ||
|
|
82a997c52a | ||
|
|
5369ac8c20 | ||
|
|
97730f2067 | ||
|
|
0534f9e7f3 | ||
|
|
ebb11c3a4a | ||
|
|
91ab1ce991 | ||
|
|
d8478e8b6f | ||
|
|
ce41401b09 | ||
|
|
1beac71051 | ||
|
|
cb277e5c43 | ||
|
|
e52f87eff2 | ||
|
|
48bed54846 | ||
|
|
bde4e831d3 | ||
|
|
421f1345b9 | ||
|
|
8f7d4cb823 | ||
|
|
0076c5793c | ||
|
|
8cf508be80 | ||
|
|
a59f167ad9 | ||
|
|
d9c8cc2520 | ||
|
|
33e78e7743 | ||
|
|
acb5644475 | ||
|
|
01c824da16 | ||
|
|
7bf0952e0f | ||
|
|
c9e794be13 | ||
|
|
a2183751f2 | ||
|
|
bf8911a06b | ||
|
|
ddb4a8e99c | ||
|
|
2a12e1b56a | ||
|
|
61b8a9bfc7 | ||
|
|
963602c4ed | ||
|
|
b462dfb560 | ||
|
|
725d73c5c7 | ||
|
|
79260a4f4f | ||
|
|
2b09521d05 | ||
|
|
138feafd14 | ||
|
|
865cca1361 | ||
|
|
e3acb4ebda | ||
|
|
ac1b7ef80a | ||
|
|
a9f041ddd4 | ||
|
|
1809404e28 | ||
|
|
0af0b18f28 | ||
|
|
c8dd399614 | ||
|
|
f111c2aa36 | ||
|
|
12e917e04c | ||
|
|
dbe00218fb | ||
|
|
fa0b958991 | ||
|
|
f343062b82 | ||
|
|
e639bba4f0 | ||
|
|
34ff2c7db4 | ||
|
|
4065956be9 | ||
|
|
9b0fd13e3f | ||
|
|
53d95574f4 | ||
|
|
ebd4dc568a | ||
|
|
9115f344bd | ||
|
|
31c3cce717 | ||
|
|
c1795be3bc | ||
|
|
75ae529d21 | ||
|
|
93eba4a2e5 | ||
|
|
5582d9894f | ||
|
|
97e01d66ef | ||
|
|
2a4deb3f9f | ||
|
|
458653506b | ||
|
|
322721b8cd | ||
|
|
601b150078 | ||
|
|
665443b5d9 | ||
|
|
caae605ffb | ||
|
|
5d3a082e24 | ||
|
|
80b198ce77 | ||
|
|
92eaaeabac | ||
|
|
8eedaeb3f8 | ||
|
|
3b83e6acf9 | ||
|
|
0bf2f64851 | ||
|
|
ce9d751c8c | ||
|
|
2b841e5b72 | ||
|
|
7ca6a73a54 | ||
|
|
79db2f4851 | ||
|
|
cf1add2ac3 | ||
|
|
50a0a4c60e | ||
|
|
ed9ec99956 | ||
|
|
79316c3c93 | ||
|
|
2914167b9b | ||
|
|
7334092ecc | ||
|
|
aeb80ee3ca | ||
|
|
a1e8057254 | ||
|
|
94b35fc3df | ||
|
|
188881c8fc | ||
|
|
555ebcb094 | ||
|
|
73cb31d05f | ||
|
|
88c4df44ff | ||
|
|
bbdd7d7680 | ||
|
|
6e2d6ef546 | ||
|
|
a412549585 | ||
|
|
fedaa03863 | ||
|
|
5152387edb | ||
|
|
10552f6f89 | ||
|
|
53101abf47 | ||
|
|
0c1e36ed75 | ||
|
|
1664cea4b1 | ||
|
|
58dc7efeb3 | ||
|
|
8bc56cd807 |
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@@ -18,3 +18,5 @@ jobs:
|
||||
npm install
|
||||
- run: |
|
||||
npm run build
|
||||
- run: |
|
||||
npm run test
|
||||
|
||||
18
.licenses/npm/@actions/core.dep.yml
generated
18
.licenses/npm/@actions/core.dep.yml
generated
@@ -1,20 +1,20 @@
|
||||
---
|
||||
name: '@actions/core'
|
||||
version: 1.6.0
|
||||
name: "@actions/core"
|
||||
version: 1.10.0
|
||||
type: npm
|
||||
summary: Actions core lib
|
||||
homepage: https://github.com/actions/toolkit/tree/main/packages/core
|
||||
license: mit
|
||||
licenses:
|
||||
- sources: LICENSE.md
|
||||
text: |-
|
||||
The MIT License (MIT)
|
||||
- sources: LICENSE.md
|
||||
text: |-
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright 2019 GitHub
|
||||
Copyright 2019 GitHub
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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 OR COPYRIGHT HOLDERS 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.
|
||||
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 OR COPYRIGHT HOLDERS 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.
|
||||
notices: []
|
||||
|
||||
2
.licenses/npm/@actions/github.dep.yml
generated
2
.licenses/npm/@actions/github.dep.yml
generated
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: '@actions/github'
|
||||
version: 5.0.0
|
||||
version: 5.0.3
|
||||
type: npm
|
||||
summary: Actions github lib
|
||||
homepage: https://github.com/actions/toolkit/tree/main/packages/github
|
||||
|
||||
4
.licenses/npm/@actions/http-client.dep.yml
generated
4
.licenses/npm/@actions/http-client.dep.yml
generated
@@ -1,9 +1,9 @@
|
||||
---
|
||||
name: '@actions/http-client'
|
||||
version: 1.0.11
|
||||
version: 2.0.1
|
||||
type: npm
|
||||
summary: Actions Http Client
|
||||
homepage: https://github.com/actions/http-client#readme
|
||||
homepage: https://github.com/actions/toolkit/tree/main/packages/http-client
|
||||
license: mit
|
||||
licenses:
|
||||
- sources: LICENSE
|
||||
|
||||
2
.licenses/npm/@octokit/core.dep.yml
generated
2
.licenses/npm/@octokit/core.dep.yml
generated
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: '@octokit/core'
|
||||
version: 3.5.1
|
||||
version: 3.6.0
|
||||
type: npm
|
||||
summary: Extendable client for GitHub's REST & GraphQL APIs
|
||||
homepage:
|
||||
|
||||
20
.licenses/npm/uuid.dep.yml
generated
Normal file
20
.licenses/npm/uuid.dep.yml
generated
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: uuid
|
||||
version: 8.3.2
|
||||
type: npm
|
||||
summary: RFC4122 (v1, v4, and v5) UUIDs
|
||||
homepage:
|
||||
license: mit
|
||||
licenses:
|
||||
- sources: LICENSE.md
|
||||
text: |
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2010-2020 Robert Kieffer and other contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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 OR COPYRIGHT HOLDERS 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.
|
||||
notices: []
|
||||
90
README.md
90
README.md
@@ -1,17 +1,13 @@
|
||||
# actions/add-to-project
|
||||
|
||||
Use this action to automatically add the current issue or pull request to a GitHub project.
|
||||
Note that this is for [GitHub projects
|
||||
(beta)](https://docs.github.com/en/issues/trying-out-the-new-projects-experience/about-projects),
|
||||
not the original GitHub projects.
|
||||
Use this action to automatically add the current issue or pull request to a [GitHub project](https://docs.github.com/en/issues/trying-out-the-new-projects-experience/about-projects).
|
||||
Note that this action does not support [GitHub projects (classic)](https://docs.github.com/en/issues/organizing-your-work-with-project-boards).
|
||||
|
||||
## Current Status
|
||||
|
||||
[](https://github.com/actions/add-to-project/actions/workflows/test.yml)
|
||||
|
||||
🚨 **This action is in beta, however the API is stable. Some breaking changes might occur between versions, but it is not likely to break as long as you use a specific SHA or version number** 🚨
|
||||
|
||||
> **NOTE:** This Action (currently) only supports auto-adding Issues to a Project which lives in the same organization as your target Repository.
|
||||
> **NOTE:** ⚠️ This action no longer uses the deprecated ProjectNext API. If you are looking for the old version of that action, use version [v0.0.5](https://github.com/actions/add-to-project/releases/tag/v0.0.5).
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -23,7 +19,9 @@ Create a workflow that runs when Issues or Pull Requests are opened or labeled i
|
||||
|
||||
Once you've configured your workflow, save it as a `.yml` file in your target Repository's `.github/workflows` directory.
|
||||
|
||||
##### Example Usage: Issue opened with labels `bug` OR `needs-triage`
|
||||
### Examples
|
||||
|
||||
#### Example Usage: Issue opened with labels `bug` OR `needs-triage`
|
||||
|
||||
```yaml
|
||||
name: Add bugs to bugs project
|
||||
@@ -38,15 +36,17 @@ jobs:
|
||||
name: Add issue to project
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/add-to-project@main
|
||||
- uses: actions/add-to-project@RELEASE_VERSION
|
||||
with:
|
||||
# You can target a repository in a different organization
|
||||
# to the issue
|
||||
project-url: https://github.com/orgs/<orgName>/projects/<projectNumber>
|
||||
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
|
||||
labeled: bug, needs-triage
|
||||
label-operator: OR
|
||||
|
||||
```
|
||||
##### Example Usage: Adds all issues opened that do not include the label `bug` OR `needs-triage`
|
||||
|
||||
#### Example Usage: Adds all issues opened that do not include the label `bug` OR `needs-triage`
|
||||
|
||||
```yaml
|
||||
name: Adds all issues that don't include the 'bug' or 'needs-triage' labels to project board
|
||||
@@ -61,7 +61,7 @@ jobs:
|
||||
name: Add issue to project
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/add-to-project@main
|
||||
- uses: actions/add-to-project@RELEASE_VERSION
|
||||
with:
|
||||
project-url: https://github.com/orgs/<orgName>/projects/<projectNumber>
|
||||
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
|
||||
@@ -69,7 +69,7 @@ jobs:
|
||||
label-operator: NOT
|
||||
```
|
||||
|
||||
##### Example Usage: Pull Requests labeled with `needs-review` and `size/XL`
|
||||
#### Example Usage: Pull Requests labeled with `needs-review` and `size/XL`
|
||||
|
||||
```yaml
|
||||
name: Add needs-review and size/XL pull requests to projects
|
||||
@@ -84,7 +84,7 @@ jobs:
|
||||
name: Add issue to project
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/add-to-project@main
|
||||
- uses: actions/add-to-project@RELEASE_VERSION
|
||||
with:
|
||||
project-url: https://github.com/orgs/<orgName>/projects/<projectNumber>
|
||||
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
|
||||
@@ -92,22 +92,29 @@ jobs:
|
||||
label-operator: AND
|
||||
```
|
||||
|
||||
#### Further reading and additional resources
|
||||
### Further reading and additional resources
|
||||
|
||||
- [Inputs](#inputs)
|
||||
- [Supported Events](#supported-events)
|
||||
- [How to point the action to a specific branch or commit sha](#how-to-point-the-action-to-a-specific-branch-or-commit-sha)
|
||||
- [Creating a PAT and adding it to your repository](#creating-a-pat-and-adding-it-to-your-repository)
|
||||
- [Development](#development)
|
||||
- [Publish to a distribution branch](#publish-to-a-distribution-branch)
|
||||
- [actions/add-to-project](#actionsadd-to-project)
|
||||
- [Current Status](#current-status)
|
||||
- [Usage](#usage)
|
||||
- [Examples](#examples)
|
||||
- [Example Usage: Issue opened with labels `bug` OR `needs-triage`](#example-usage-issue-opened-with-labels-bug-or-needs-triage)
|
||||
- [Example Usage: Adds all issues opened that do not include the label `bug` OR `needs-triage`](#example-usage-adds-all-issues-opened-that-do-not-include-the-label-bug-or-needs-triage)
|
||||
- [Example Usage: Pull Requests labeled with `needs-review` and `size/XL`](#example-usage-pull-requests-labeled-with-needs-review-and-sizexl)
|
||||
- [Further reading and additional resources](#further-reading-and-additional-resources)
|
||||
- [Inputs](#inputs)
|
||||
- [Supported Events](#supported-events)
|
||||
- [Creating a PAT and adding it to your repository](#creating-a-pat-and-adding-it-to-your-repository)
|
||||
- [Development](#development)
|
||||
- [Publish to a distribution branch](#publish-to-a-distribution-branch)
|
||||
- [License](#license)
|
||||
|
||||
## Inputs
|
||||
|
||||
- <a name="project-url">`project-url`</a> **(required)** is the URL of the GitHub project to add issues to.
|
||||
- <a name="project-url">`project-url`</a> **(required)** is the URL of the GitHub project to add issues to.
|
||||
_eg: `https://github.com/orgs|users/<ownerName>/projects/<projectNumber>`_
|
||||
- <a name="github-token">`github-token`</a> **(required)** is a [personal access
|
||||
token](https://github.com/settings/tokens/new) with the `repo`, `write:org` and
|
||||
`read:org` scopes.
|
||||
token](https://github.com/settings/tokens/new) with `repo` and `project` scopes.
|
||||
_See [Creating a PAT and adding it to your repository](#creating-a-pat-and-adding-it-to-your-repository) for more details_
|
||||
- <a name="labeled">`labeled`</a> **(optional)** is a comma-separated list of labels used to filter applicable issues. When this key is provided, an issue must have _one_ of the labels in the list to be added to the project. Omitting this key means that any issue will be added.
|
||||
- <a name="labeled">`label-operator`</a> **(optional)** is the behavior of the labels filter, either `AND`, `OR` or `NOT` that controls if the issue should be matched with `all` `labeled` input or any of them, default is `OR`.
|
||||
@@ -127,44 +134,13 @@ and the following [`pull_request` events](https://docs.github.com/en/actions/usi
|
||||
|
||||
Using these events ensure that a given issue or pull request, in the workflow's repo, is added to the [specified project](#project-url). If [labeled input(s)](#labeled) are defined, then issues will only be added if they contain at least _one_ of the labels in the list.
|
||||
|
||||
## How to point the action to a specific branch or commit sha
|
||||
|
||||
Pointing to a branch name generally isn't the safest way to refer to an action, but this is how you can use this action now before we've begun creating releases.
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
add-to-project:
|
||||
name: Add issue to project
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/add-to-project@main
|
||||
with:
|
||||
project-url: https://github.com/orgs/<orgName>/projects/<projectNumber>
|
||||
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
|
||||
```
|
||||
|
||||
Another option would be to point to a full [commit SHA](https://docs.github.com/en/get-started/quickstart/github-glossary#commit):
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
add-to-project:
|
||||
name: Add issue to project
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/add-to-project@<commitSHA>
|
||||
with:
|
||||
project-url: https://github.com/orgs/<orgName>/projects/<projectNumber>
|
||||
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
|
||||
```
|
||||
|
||||
## Creating a PAT and adding it to your repository
|
||||
|
||||
- create a new [personal access
|
||||
token](https://github.com/settings/tokens/new) with `repo`, `write:org` and
|
||||
`read:org` scopes
|
||||
token](https://github.com/settings/tokens/new) with `repo` and `project` scopes
|
||||
_See [Creating a personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) for more information_
|
||||
|
||||
- add the newly created PAT as a repository secret, this secret will be referenced by the [github-token input](#github-token)
|
||||
- add the newly created PAT as a repository secret, this secret will be referenced by the [github-token input](#github-token)
|
||||
_See [Encrypted secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) for more information_
|
||||
|
||||
## Development
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as github from '@actions/github'
|
||||
|
||||
import {addToProject, mustGetOwnerTypeQuery} from '../src/add-to-project'
|
||||
|
||||
describe('addToProject', () => {
|
||||
@@ -11,7 +12,7 @@ describe('addToProject', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
mockGetInput({
|
||||
'project-url': 'https://github.com/orgs/github/projects/1',
|
||||
'project-url': 'https://github.com/orgs/actions/projects/1',
|
||||
'github-token': 'gh_token'
|
||||
})
|
||||
|
||||
@@ -23,46 +24,19 @@ describe('addToProject', () => {
|
||||
jest.restoreAllMocks()
|
||||
})
|
||||
|
||||
test('adds an issue to the project', async () => {
|
||||
mockGraphQL(
|
||||
{
|
||||
test: /getProject/,
|
||||
return: {
|
||||
organization: {
|
||||
projectNext: {
|
||||
id: 'project-next-id'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /addProjectNextItem/,
|
||||
return: {
|
||||
addProjectNextItem: {
|
||||
projectNextItem: {
|
||||
id: 'project-next-item-id'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
await addToProject()
|
||||
|
||||
expect(outputs.itemId).toEqual('project-next-item-id')
|
||||
})
|
||||
|
||||
test('adds matching issues with a label filter without label-operator', async () => {
|
||||
mockGetInput({
|
||||
'project-url': 'https://github.com/orgs/github/projects/1',
|
||||
'github-token': 'gh_token',
|
||||
labeled: 'bug, new'
|
||||
})
|
||||
|
||||
test('adds an issue from the same organization to the project', async () => {
|
||||
github.context.payload = {
|
||||
issue: {
|
||||
number: 1,
|
||||
labels: [{name: 'bug'}]
|
||||
labels: [{name: 'bug'}],
|
||||
// eslint-disable-next-line camelcase
|
||||
html_url: 'https://github.com/actions/add-to-project/issues/74'
|
||||
},
|
||||
repository: {
|
||||
name: 'add-to-project',
|
||||
owner: {
|
||||
login: 'actions'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,18 +45,18 @@ describe('addToProject', () => {
|
||||
test: /getProject/,
|
||||
return: {
|
||||
organization: {
|
||||
projectNext: {
|
||||
id: 'project-next-id'
|
||||
projectV2: {
|
||||
id: 'project-id'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /addProjectNextItem/,
|
||||
test: /addProjectV2ItemById/,
|
||||
return: {
|
||||
addProjectNextItem: {
|
||||
projectNextItem: {
|
||||
id: 'project-next-item-id'
|
||||
addProjectV2ItemById: {
|
||||
item: {
|
||||
id: 'project-item-id'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,12 +65,106 @@ describe('addToProject', () => {
|
||||
|
||||
await addToProject()
|
||||
|
||||
expect(outputs.itemId).toEqual('project-next-item-id')
|
||||
expect(outputs.itemId).toEqual('project-item-id')
|
||||
})
|
||||
|
||||
test('adds an issue from a different organization to the project', async () => {
|
||||
github.context.payload = {
|
||||
issue: {
|
||||
number: 2221,
|
||||
labels: [{name: 'bug'}],
|
||||
// eslint-disable-next-line camelcase
|
||||
html_url: 'https://github.com/octokit/octokit.js/issues/2221'
|
||||
},
|
||||
repository: {
|
||||
name: 'octokit.js',
|
||||
owner: {
|
||||
login: 'octokit'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mockGraphQL(
|
||||
{
|
||||
test: /getProject/,
|
||||
return: {
|
||||
organization: {
|
||||
projectV2: {
|
||||
id: 'project-id'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /addProjectV2DraftIssue/,
|
||||
return: {
|
||||
addProjectV2DraftIssue: {
|
||||
projectItem: {
|
||||
id: 'project-item-id'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
await addToProject()
|
||||
|
||||
expect(outputs.itemId).toEqual('project-item-id')
|
||||
})
|
||||
|
||||
test('adds matching issues with a label filter without label-operator', async () => {
|
||||
mockGetInput({
|
||||
'project-url': 'https://github.com/orgs/actions/projects/1',
|
||||
'github-token': 'gh_token',
|
||||
labeled: 'bug, new'
|
||||
})
|
||||
|
||||
github.context.payload = {
|
||||
issue: {
|
||||
number: 1,
|
||||
labels: [{name: 'bug'}],
|
||||
// eslint-disable-next-line camelcase
|
||||
html_url: 'https://github.com/actions/add-to-project/issues/74'
|
||||
},
|
||||
repository: {
|
||||
name: 'add-to-project',
|
||||
owner: {
|
||||
login: 'actions'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mockGraphQL(
|
||||
{
|
||||
test: /getProject/,
|
||||
return: {
|
||||
organization: {
|
||||
projectV2: {
|
||||
id: 'project-id'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /addProjectV2ItemById/,
|
||||
return: {
|
||||
addProjectV2ItemById: {
|
||||
item: {
|
||||
id: 'project-item-id'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
await addToProject()
|
||||
|
||||
expect(outputs.itemId).toEqual('project-item-id')
|
||||
})
|
||||
|
||||
test('adds matching pull-requests with a label filter without label-operator', async () => {
|
||||
mockGetInput({
|
||||
'project-url': 'https://github.com/orgs/github/projects/1',
|
||||
'project-url': 'https://github.com/orgs/actions/projects/1',
|
||||
'github-token': 'gh_token',
|
||||
labeled: 'bug, new'
|
||||
})
|
||||
@@ -105,7 +173,15 @@ describe('addToProject', () => {
|
||||
// eslint-disable-next-line camelcase
|
||||
pull_request: {
|
||||
number: 1,
|
||||
labels: [{name: 'bug'}]
|
||||
labels: [{name: 'bug'}],
|
||||
// eslint-disable-next-line camelcase
|
||||
html_url: 'https://github.com/actions/add-to-project/pull/136'
|
||||
},
|
||||
repository: {
|
||||
name: 'add-to-project',
|
||||
owner: {
|
||||
login: 'actions'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,18 +190,18 @@ describe('addToProject', () => {
|
||||
test: /getProject/,
|
||||
return: {
|
||||
organization: {
|
||||
projectNext: {
|
||||
id: 'project-next-id'
|
||||
projectV2: {
|
||||
id: 'project-id'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /addProjectNextItem/,
|
||||
test: /addProjectV2ItemById/,
|
||||
return: {
|
||||
addProjectNextItem: {
|
||||
projectNextItem: {
|
||||
id: 'project-next-item-id'
|
||||
addProjectV2ItemById: {
|
||||
item: {
|
||||
id: 'project-item-id'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -134,12 +210,12 @@ describe('addToProject', () => {
|
||||
|
||||
await addToProject()
|
||||
|
||||
expect(outputs.itemId).toEqual('project-next-item-id')
|
||||
expect(outputs.itemId).toEqual('project-item-id')
|
||||
})
|
||||
|
||||
test('does not add un-matching issues with a label filter without label-operator', async () => {
|
||||
mockGetInput({
|
||||
'project-url': 'https://github.com/orgs/github/projects/1',
|
||||
'project-url': 'https://github.com/orgs/actions/projects/1',
|
||||
'github-token': 'gh_token',
|
||||
labeled: 'bug'
|
||||
})
|
||||
@@ -147,7 +223,15 @@ describe('addToProject', () => {
|
||||
github.context.payload = {
|
||||
issue: {
|
||||
number: 1,
|
||||
labels: []
|
||||
labels: [],
|
||||
// eslint-disable-next-line camelcase
|
||||
html_url: 'https://github.com/actions/add-to-project/issues/74'
|
||||
},
|
||||
repository: {
|
||||
name: 'add-to-project',
|
||||
owner: {
|
||||
login: 'actions'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,7 +244,7 @@ describe('addToProject', () => {
|
||||
|
||||
test('adds matching issues with labels filter with AND label-operator', async () => {
|
||||
mockGetInput({
|
||||
'project-url': 'https://github.com/orgs/github/projects/1',
|
||||
'project-url': 'https://github.com/orgs/actions/projects/1',
|
||||
'github-token': 'gh_token',
|
||||
labeled: 'bug, new',
|
||||
'label-operator': 'AND'
|
||||
@@ -169,7 +253,15 @@ describe('addToProject', () => {
|
||||
github.context.payload = {
|
||||
issue: {
|
||||
number: 1,
|
||||
labels: [{name: 'bug'}, {name: 'new'}]
|
||||
labels: [{name: 'bug'}, {name: 'new'}],
|
||||
// eslint-disable-next-line camelcase
|
||||
html_url: 'https://github.com/actions/add-to-project/issues/74'
|
||||
},
|
||||
repository: {
|
||||
name: 'add-to-project',
|
||||
owner: {
|
||||
login: 'actions'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,18 +270,18 @@ describe('addToProject', () => {
|
||||
test: /getProject/,
|
||||
return: {
|
||||
organization: {
|
||||
projectNext: {
|
||||
id: 'project-next-id'
|
||||
projectV2: {
|
||||
id: 'project-id'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /addProjectNextItem/,
|
||||
test: /addProjectV2ItemById/,
|
||||
return: {
|
||||
addProjectNextItem: {
|
||||
projectNextItem: {
|
||||
id: 'project-next-item-id'
|
||||
addProjectV2ItemById: {
|
||||
item: {
|
||||
id: 'project-item-id'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -198,12 +290,12 @@ describe('addToProject', () => {
|
||||
|
||||
await addToProject()
|
||||
|
||||
expect(outputs.itemId).toEqual('project-next-item-id')
|
||||
expect(outputs.itemId).toEqual('project-item-id')
|
||||
})
|
||||
|
||||
test('does not add un-matching issues with labels filter with AND label-operator', async () => {
|
||||
mockGetInput({
|
||||
'project-url': 'https://github.com/orgs/github/projects/1',
|
||||
'project-url': 'https://github.com/orgs/actions/projects/1',
|
||||
'github-token': 'gh_token',
|
||||
labeled: 'bug, new',
|
||||
'label-operator': 'AND'
|
||||
@@ -212,7 +304,15 @@ describe('addToProject', () => {
|
||||
github.context.payload = {
|
||||
issue: {
|
||||
number: 1,
|
||||
labels: [{name: 'bug'}, {name: 'other'}]
|
||||
labels: [{name: 'bug'}, {name: 'other'}],
|
||||
// eslint-disable-next-line camelcase
|
||||
html_url: 'https://github.com/actions/add-to-project/issues/74'
|
||||
},
|
||||
repository: {
|
||||
name: 'add-to-project',
|
||||
owner: {
|
||||
login: 'actions'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,7 +325,7 @@ describe('addToProject', () => {
|
||||
|
||||
test('does not add matching issues with labels filter with NOT label-operator', async () => {
|
||||
mockGetInput({
|
||||
'project-url': 'https://github.com/orgs/github/projects/1',
|
||||
'project-url': 'https://github.com/orgs/actions/projects/1',
|
||||
'github-token': 'gh_token',
|
||||
labeled: 'bug, new',
|
||||
'label-operator': 'NOT'
|
||||
@@ -234,7 +334,15 @@ describe('addToProject', () => {
|
||||
github.context.payload = {
|
||||
issue: {
|
||||
number: 1,
|
||||
labels: [{name: 'bug'}]
|
||||
labels: [{name: 'bug'}],
|
||||
// eslint-disable-next-line camelcase
|
||||
html_url: 'https://github.com/actions/add-to-project/issues/74'
|
||||
},
|
||||
repository: {
|
||||
name: 'add-to-project',
|
||||
owner: {
|
||||
login: 'actions'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,7 +355,7 @@ describe('addToProject', () => {
|
||||
|
||||
test('adds issues that do not have labels present in the label list with NOT label-operator', async () => {
|
||||
mockGetInput({
|
||||
'project-url': 'https://github.com/orgs/github/projects/1',
|
||||
'project-url': 'https://github.com/orgs/actions/projects/1',
|
||||
'github-token': 'gh_token',
|
||||
labeled: 'bug, new',
|
||||
'label-operator': 'NOT'
|
||||
@@ -256,7 +364,15 @@ describe('addToProject', () => {
|
||||
github.context.payload = {
|
||||
issue: {
|
||||
number: 1,
|
||||
labels: [{name: 'other'}]
|
||||
labels: [{name: 'other'}],
|
||||
// eslint-disable-next-line camelcase
|
||||
html_url: 'https://github.com/actions/add-to-project/issues/74'
|
||||
},
|
||||
repository: {
|
||||
name: 'add-to-project',
|
||||
owner: {
|
||||
login: 'actions'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,17 +381,17 @@ describe('addToProject', () => {
|
||||
test: /getProject/,
|
||||
return: {
|
||||
organization: {
|
||||
projectNext: {
|
||||
projectV2: {
|
||||
id: 'project-next-id'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /addProjectNextItem/,
|
||||
test: /addProjectV2ItemById/,
|
||||
return: {
|
||||
addProjectNextItem: {
|
||||
projectNextItem: {
|
||||
addProjectV2ItemById: {
|
||||
item: {
|
||||
id: 'project-next-item-id'
|
||||
}
|
||||
}
|
||||
@@ -290,7 +406,7 @@ describe('addToProject', () => {
|
||||
|
||||
test('adds matching issues with multiple label filters', async () => {
|
||||
mockGetInput({
|
||||
'project-url': 'https://github.com/orgs/github/projects/1',
|
||||
'project-url': 'https://github.com/orgs/actions/projects/1',
|
||||
'github-token': 'gh_token',
|
||||
labeled: 'accessibility,backend,bug'
|
||||
})
|
||||
@@ -298,7 +414,15 @@ describe('addToProject', () => {
|
||||
github.context.payload = {
|
||||
issue: {
|
||||
number: 1,
|
||||
labels: [{name: 'accessibility'}, {name: 'backend'}]
|
||||
labels: [{name: 'accessibility'}, {name: 'backend'}],
|
||||
// eslint-disable-next-line camelcase
|
||||
html_url: 'https://github.com/actions/add-to-project/issues/74'
|
||||
},
|
||||
repository: {
|
||||
name: 'add-to-project',
|
||||
owner: {
|
||||
login: 'actions'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,18 +431,18 @@ describe('addToProject', () => {
|
||||
test: /getProject/,
|
||||
return: {
|
||||
organization: {
|
||||
projectNext: {
|
||||
id: 'project-next-id'
|
||||
projectV2: {
|
||||
id: 'project-id'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /addProjectNextItem/,
|
||||
test: /addProjectV2ItemById/,
|
||||
return: {
|
||||
addProjectNextItem: {
|
||||
projectNextItem: {
|
||||
id: 'project-next-item-id'
|
||||
addProjectV2ItemById: {
|
||||
item: {
|
||||
id: 'project-item-id'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -330,13 +454,15 @@ describe('addToProject', () => {
|
||||
await addToProject()
|
||||
|
||||
expect(gqlMock).toHaveBeenCalled()
|
||||
expect(infoSpy).not.toHaveBeenCalled()
|
||||
expect(outputs.itemId).toEqual('project-next-item-id')
|
||||
expect(infoSpy).toHaveBeenCalledWith('Creating project item')
|
||||
// We shouldn't have any logs relating to the issue being skipped
|
||||
expect(infoSpy.mock.calls.length).toEqual(1)
|
||||
expect(outputs.itemId).toEqual('project-item-id')
|
||||
})
|
||||
|
||||
test('does not add un-matching issues with multiple label filters', async () => {
|
||||
mockGetInput({
|
||||
'project-url': 'https://github.com/orgs/github/projects/1',
|
||||
'project-url': 'https://github.com/orgs/actions/projects/1',
|
||||
'github-token': 'gh_token',
|
||||
labeled: 'accessibility, backend, bug'
|
||||
})
|
||||
@@ -344,7 +470,15 @@ describe('addToProject', () => {
|
||||
github.context.payload = {
|
||||
issue: {
|
||||
number: 1,
|
||||
labels: [{name: 'data'}, {name: 'frontend'}, {name: 'improvement'}]
|
||||
labels: [{name: 'data'}, {name: 'frontend'}, {name: 'improvement'}],
|
||||
// eslint-disable-next-line camelcase
|
||||
html_url: 'https://github.com/actions/add-to-project/issues/74'
|
||||
},
|
||||
repository: {
|
||||
name: 'add-to-project',
|
||||
owner: {
|
||||
login: 'actions'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -359,7 +493,7 @@ describe('addToProject', () => {
|
||||
|
||||
test('handles spaces and extra commas gracefully in label filter input', async () => {
|
||||
mockGetInput({
|
||||
'project-url': 'https://github.com/orgs/github/projects/1',
|
||||
'project-url': 'https://github.com/orgs/actions/projects/1',
|
||||
'github-token': 'gh_token',
|
||||
labeled: 'accessibility , backend ,, . , bug'
|
||||
})
|
||||
@@ -368,7 +502,15 @@ describe('addToProject', () => {
|
||||
issue: {
|
||||
number: 1,
|
||||
labels: [{name: 'accessibility'}, {name: 'backend'}, {name: 'bug'}],
|
||||
'label-operator': 'AND'
|
||||
'label-operator': 'AND',
|
||||
// eslint-disable-next-line camelcase
|
||||
html_url: 'https://github.com/actions/add-to-project/issues/74'
|
||||
},
|
||||
repository: {
|
||||
name: 'add-to-project',
|
||||
owner: {
|
||||
login: 'actions'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -377,18 +519,18 @@ describe('addToProject', () => {
|
||||
test: /getProject/,
|
||||
return: {
|
||||
organization: {
|
||||
projectNext: {
|
||||
id: 'project-next-id'
|
||||
projectV2: {
|
||||
id: 'project-id'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /addProjectNextItem/,
|
||||
test: /addProjectV2ItemById/,
|
||||
return: {
|
||||
addProjectNextItem: {
|
||||
projectNextItem: {
|
||||
id: 'project-next-item-id'
|
||||
addProjectV2ItemById: {
|
||||
item: {
|
||||
id: 'project-item-id'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -400,8 +542,10 @@ describe('addToProject', () => {
|
||||
await addToProject()
|
||||
|
||||
expect(gqlMock).toHaveBeenCalled()
|
||||
expect(infoSpy).not.toHaveBeenCalled()
|
||||
expect(outputs.itemId).toEqual('project-next-item-id')
|
||||
expect(infoSpy).toHaveBeenCalledWith('Creating project item')
|
||||
// We shouldn't have any logs relating to the issue being skipped
|
||||
expect(infoSpy.mock.calls.length).toEqual(1)
|
||||
expect(outputs.itemId).toEqual('project-item-id')
|
||||
})
|
||||
|
||||
test(`throws an error when url isn't a valid project url`, async () => {
|
||||
@@ -413,7 +557,15 @@ describe('addToProject', () => {
|
||||
github.context.payload = {
|
||||
issue: {
|
||||
number: 1,
|
||||
labels: []
|
||||
labels: [],
|
||||
// eslint-disable-next-line camelcase
|
||||
html_url: 'https://github.com/actions/add-to-project/issues/74'
|
||||
},
|
||||
repository: {
|
||||
name: 'add-to-project',
|
||||
owner: {
|
||||
login: 'actions'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -435,7 +587,15 @@ describe('addToProject', () => {
|
||||
github.context.payload = {
|
||||
issue: {
|
||||
number: 1,
|
||||
labels: []
|
||||
labels: [],
|
||||
// eslint-disable-next-line camelcase
|
||||
html_url: 'https://github.com/actions/add-to-project/issues/74'
|
||||
},
|
||||
repository: {
|
||||
name: 'add-to-project',
|
||||
owner: {
|
||||
login: 'actions'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -450,7 +610,7 @@ describe('addToProject', () => {
|
||||
|
||||
test('constructs the correct graphQL query given an organization owner', async () => {
|
||||
mockGetInput({
|
||||
'project-url': 'https://github.com/orgs/github/projects/1',
|
||||
'project-url': 'https://github.com/orgs/actions/projects/1',
|
||||
'github-token': 'gh_token',
|
||||
labeled: 'bug, new'
|
||||
})
|
||||
@@ -458,7 +618,15 @@ describe('addToProject', () => {
|
||||
github.context.payload = {
|
||||
issue: {
|
||||
number: 1,
|
||||
labels: [{name: 'bug'}]
|
||||
labels: [{name: 'bug'}],
|
||||
// eslint-disable-next-line camelcase
|
||||
html_url: 'https://github.com/actions/add-to-project/issues/74'
|
||||
},
|
||||
repository: {
|
||||
name: 'add-to-project',
|
||||
owner: {
|
||||
login: 'actions'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -467,18 +635,18 @@ describe('addToProject', () => {
|
||||
test: /getProject/,
|
||||
return: {
|
||||
organization: {
|
||||
projectNext: {
|
||||
id: 'project-next-id'
|
||||
projectV2: {
|
||||
id: 'project-id'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /addProjectNextItem/,
|
||||
test: /addProjectV2ItemById/,
|
||||
return: {
|
||||
addProjectNextItem: {
|
||||
projectNextItem: {
|
||||
id: 'project-next-item-id'
|
||||
addProjectV2ItemById: {
|
||||
item: {
|
||||
id: 'project-item-id'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -487,8 +655,8 @@ describe('addToProject', () => {
|
||||
|
||||
await addToProject()
|
||||
|
||||
expect(gqlMock).toHaveBeenNthCalledWith(1, expect.stringContaining('organization(login: $ownerName)'), {
|
||||
ownerName: 'github',
|
||||
expect(gqlMock).toHaveBeenNthCalledWith(1, expect.stringContaining('organization(login: $projectOwnerName)'), {
|
||||
projectOwnerName: 'actions',
|
||||
projectNumber: 1
|
||||
})
|
||||
})
|
||||
@@ -503,7 +671,15 @@ describe('addToProject', () => {
|
||||
github.context.payload = {
|
||||
issue: {
|
||||
number: 1,
|
||||
labels: [{name: 'bug'}]
|
||||
labels: [{name: 'bug'}],
|
||||
// eslint-disable-next-line camelcase
|
||||
html_url: 'https://github.com/monalisa/add-to-project/issues/74'
|
||||
},
|
||||
repository: {
|
||||
name: 'add-to-project',
|
||||
owner: {
|
||||
login: 'monalisa'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -512,17 +688,71 @@ describe('addToProject', () => {
|
||||
test: /getProject/,
|
||||
return: {
|
||||
organization: {
|
||||
projectNext: {
|
||||
projectV2: {
|
||||
id: 'project-id'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /addProjectV2ItemById/,
|
||||
return: {
|
||||
addProjectV2ItemById: {
|
||||
item: {
|
||||
id: 'project-item-id'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
await addToProject()
|
||||
|
||||
expect(gqlMock).toHaveBeenNthCalledWith(1, expect.stringContaining('user(login: $projectOwnerName)'), {
|
||||
projectOwnerName: 'monalisa',
|
||||
projectNumber: 1
|
||||
})
|
||||
})
|
||||
|
||||
test('compares labels case-insensitively', async () => {
|
||||
mockGetInput({
|
||||
'project-url': 'https://github.com/orgs/actions/projects/1',
|
||||
'github-token': 'gh_token',
|
||||
labeled: 'FOO, Bar, baz',
|
||||
'label-operator': 'AND'
|
||||
})
|
||||
|
||||
github.context.payload = {
|
||||
issue: {
|
||||
number: 1,
|
||||
labels: [{name: 'foo'}, {name: 'BAR'}, {name: 'baz'}],
|
||||
// eslint-disable-next-line camelcase
|
||||
html_url: 'https://github.com/actions/add-to-project/issues/74'
|
||||
},
|
||||
repository: {
|
||||
name: 'add-to-project',
|
||||
owner: {
|
||||
login: 'actions'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mockGraphQL(
|
||||
{
|
||||
test: /getProject/,
|
||||
return: {
|
||||
organization: {
|
||||
projectV2: {
|
||||
id: 'project-next-id'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /addProjectNextItem/,
|
||||
test: /addProjectV2ItemById/,
|
||||
return: {
|
||||
addProjectNextItem: {
|
||||
projectNextItem: {
|
||||
addProjectV2ItemById: {
|
||||
item: {
|
||||
id: 'project-next-item-id'
|
||||
}
|
||||
}
|
||||
@@ -532,10 +762,7 @@ describe('addToProject', () => {
|
||||
|
||||
await addToProject()
|
||||
|
||||
expect(gqlMock).toHaveBeenNthCalledWith(1, expect.stringContaining('user(login: $ownerName)'), {
|
||||
ownerName: 'monalisa',
|
||||
projectNumber: 1
|
||||
})
|
||||
expect(outputs.itemId).toEqual('project-next-item-id')
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name: Add To GitHub Projects Beta
|
||||
description: Automatically add issues and PRs to GitHub projects beta
|
||||
name: Add To GitHub projects
|
||||
description: Automatically add issues and PRs to GitHub projects
|
||||
author: GitHub
|
||||
branding:
|
||||
icon: table
|
||||
|
||||
1753
dist/index.js
generated
vendored
1753
dist/index.js
generated
vendored
File diff suppressed because it is too large
Load Diff
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
13
dist/licenses.txt
generated
vendored
13
dist/licenses.txt
generated
vendored
@@ -562,6 +562,19 @@ Permission to use, copy, modify, and/or distribute this software for any purpose
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
|
||||
uuid
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2010-2020 Robert Kieffer and other contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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 OR COPYRIGHT HOLDERS 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.
|
||||
|
||||
|
||||
webidl-conversions
|
||||
BSD-2-Clause
|
||||
# The BSD 2-Clause License
|
||||
|
||||
1447
package-lock.json
generated
1447
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
24
package.json
24
package.json
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "@actions/add-to-project",
|
||||
"description": "Automatically issues and PRs to GitHub projects",
|
||||
"description": "Automatically adds issues and PRs to GitHub projects",
|
||||
"version": "0.0.0",
|
||||
"author": "GitHub and contributors",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.6.0",
|
||||
"@actions/github": "^5.0.0"
|
||||
"@actions/core": "^1.10.0",
|
||||
"@actions/github": "^5.0.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.0.0 <17.0.0",
|
||||
@@ -14,18 +14,18 @@
|
||||
"devDependencies": {
|
||||
"@github/prettier-config": "^0.0.4",
|
||||
"@types/jest": "^27.5.0",
|
||||
"@types/node": "~16.11.41",
|
||||
"@typescript-eslint/parser": "^5.28.0",
|
||||
"@vercel/ncc": "^0.33.4",
|
||||
"concurrently": "^7.2.2",
|
||||
"eslint": "^8.17.0",
|
||||
"eslint-plugin-github": "^4.3.6",
|
||||
"eslint-plugin-jest": "^26.5.3",
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"@types/node": "~16.18.3",
|
||||
"@typescript-eslint/parser": "^5.42.0",
|
||||
"@vercel/ncc": "^0.34.0",
|
||||
"concurrently": "^7.5.0",
|
||||
"eslint": "^8.26.0",
|
||||
"eslint-plugin-github": "^4.4.0",
|
||||
"eslint-plugin-jest": "^27.1.3",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"jest": "^27.5.1",
|
||||
"prettier": "2.7.1",
|
||||
"ts-jest": "^27.1.4",
|
||||
"typescript": "^4.7.3"
|
||||
"typescript": "^4.8.4"
|
||||
},
|
||||
"keywords": [
|
||||
"actions",
|
||||
|
||||
@@ -8,21 +8,29 @@ const urlParse =
|
||||
|
||||
interface ProjectNodeIDResponse {
|
||||
organization?: {
|
||||
projectNext: {
|
||||
projectV2: {
|
||||
id: string
|
||||
}
|
||||
}
|
||||
|
||||
user?: {
|
||||
projectNext: {
|
||||
projectV2: {
|
||||
id: string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface ProjectAddItemResponse {
|
||||
addProjectNextItem: {
|
||||
projectNextItem: {
|
||||
addProjectV2ItemById: {
|
||||
item: {
|
||||
id: string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface ProjectV2AddDraftIssueResponse {
|
||||
addProjectV2DraftIssue: {
|
||||
projectItem: {
|
||||
id: string
|
||||
}
|
||||
}
|
||||
@@ -35,14 +43,17 @@ export async function addToProject(): Promise<void> {
|
||||
core
|
||||
.getInput('labeled')
|
||||
.split(',')
|
||||
.map(l => l.trim())
|
||||
.map(l => l.trim().toLowerCase())
|
||||
.filter(l => l.length > 0) ?? []
|
||||
const labelOperator = core.getInput('label-operator').trim().toLocaleLowerCase()
|
||||
|
||||
const octokit = github.getOctokit(ghToken)
|
||||
const urlMatch = projectUrl.match(urlParse)
|
||||
|
||||
const issue = github.context.payload.issue ?? github.context.payload.pull_request
|
||||
const issueLabels: string[] = (issue?.labels ?? []).map((l: {name: string}) => l.name)
|
||||
const issueLabels: string[] = (issue?.labels ?? []).map((l: {name: string}) => l.name.toLowerCase())
|
||||
const issueOwnerName = github.context.payload.repository?.owner.login
|
||||
|
||||
core.debug(`Issue/PR owner: ${issueOwnerName}`)
|
||||
|
||||
// Ensure the issue matches our `labeled` filter based on the label-operator.
|
||||
if (labelOperator === 'and') {
|
||||
@@ -64,60 +75,89 @@ export async function addToProject(): Promise<void> {
|
||||
|
||||
core.debug(`Project URL: ${projectUrl}`)
|
||||
|
||||
const urlMatch = projectUrl.match(urlParse)
|
||||
|
||||
if (!urlMatch) {
|
||||
throw new Error(
|
||||
`Invalid project URL: ${projectUrl}. Project URL should match the format https://github.com/<orgs-or-users>/<ownerName>/projects/<projectNumber>`
|
||||
)
|
||||
}
|
||||
|
||||
const ownerName = urlMatch.groups?.ownerName
|
||||
const projectOwnerName = urlMatch.groups?.ownerName
|
||||
const projectNumber = parseInt(urlMatch.groups?.projectNumber ?? '', 10)
|
||||
const ownerType = urlMatch.groups?.ownerType
|
||||
const ownerTypeQuery = mustGetOwnerTypeQuery(ownerType)
|
||||
|
||||
core.debug(`Org name: ${ownerName}`)
|
||||
core.debug(`Project owner: ${projectOwnerName}`)
|
||||
core.debug(`Project number: ${projectNumber}`)
|
||||
core.debug(`Owner type: ${ownerType}`)
|
||||
core.debug(`Project owner type: ${ownerType}`)
|
||||
|
||||
// First, use the GraphQL API to request the project's node ID.
|
||||
const idResp = await octokit.graphql<ProjectNodeIDResponse>(
|
||||
`query getProject($ownerName: String!, $projectNumber: Int!) {
|
||||
${ownerTypeQuery}(login: $ownerName) {
|
||||
projectNext(number: $projectNumber) {
|
||||
`query getProject($projectOwnerName: String!, $projectNumber: Int!) {
|
||||
${ownerTypeQuery}(login: $projectOwnerName) {
|
||||
projectV2(number: $projectNumber) {
|
||||
id
|
||||
}
|
||||
}
|
||||
}`,
|
||||
{
|
||||
ownerName,
|
||||
projectOwnerName,
|
||||
projectNumber
|
||||
}
|
||||
)
|
||||
|
||||
const projectId = idResp[ownerTypeQuery]?.projectNext.id
|
||||
const projectId = idResp[ownerTypeQuery]?.projectV2.id
|
||||
const contentId = issue?.node_id
|
||||
|
||||
core.debug(`Project node ID: ${projectId}`)
|
||||
core.debug(`Content ID: ${contentId}`)
|
||||
|
||||
// Next, use the GraphQL API to add the issue to the project.
|
||||
const addResp = await octokit.graphql<ProjectAddItemResponse>(
|
||||
`mutation addIssueToProject($input: AddProjectNextItemInput!) {
|
||||
addProjectNextItem(input: $input) {
|
||||
projectNextItem {
|
||||
id
|
||||
// If the issue has the same owner as the project, we can directly
|
||||
// add a project item. Otherwise, we add a draft issue.
|
||||
if (issueOwnerName === projectOwnerName) {
|
||||
core.info('Creating project item')
|
||||
|
||||
const addResp = await octokit.graphql<ProjectAddItemResponse>(
|
||||
`mutation addIssueToProject($input: AddProjectV2ItemByIdInput!) {
|
||||
addProjectV2ItemById(input: $input) {
|
||||
item {
|
||||
id
|
||||
}
|
||||
}
|
||||
}`,
|
||||
{
|
||||
input: {
|
||||
projectId,
|
||||
contentId
|
||||
}
|
||||
}
|
||||
}`,
|
||||
{
|
||||
input: {
|
||||
contentId,
|
||||
projectId
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
core.setOutput('itemId', addResp.addProjectNextItem.projectNextItem.id)
|
||||
core.setOutput('itemId', addResp.addProjectV2ItemById.item.id)
|
||||
} else {
|
||||
core.info('Creating draft issue in project')
|
||||
|
||||
const addResp = await octokit.graphql<ProjectV2AddDraftIssueResponse>(
|
||||
`mutation addDraftIssueToProject($projectId: ID!, $title: String!) {
|
||||
addProjectV2DraftIssue(input: {
|
||||
projectId: $projectId,
|
||||
title: $title
|
||||
}) {
|
||||
projectItem {
|
||||
id
|
||||
}
|
||||
}
|
||||
}`,
|
||||
{
|
||||
projectId,
|
||||
title: issue?.html_url
|
||||
}
|
||||
)
|
||||
|
||||
core.setOutput('itemId', addResp.addProjectV2DraftIssue.projectItem.id)
|
||||
}
|
||||
}
|
||||
|
||||
export function mustGetOwnerTypeQuery(ownerType?: string): 'organization' | 'user' {
|
||||
|
||||
Reference in New Issue
Block a user