Skip to content

Commit 5475741

Browse files
authored
feat: find closed projects (#57)
1 parent 82311f5 commit 5475741

File tree

9 files changed

+127
-55
lines changed

9 files changed

+127
-55
lines changed

.github/workflows/integration-tests.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,14 @@ jobs:
467467
fail-if-project-not-found: false
468468
owner: ${{ steps.copy-project.outputs.owner }}
469469
project-number: 99999
470+
471+
- name: Find Closed Project
472+
uses: ./find-project/
473+
id: find-closed-project
474+
with:
475+
owner: ${{ steps.copy-project.outputs.owner }}
476+
title: ${{ steps.copy-project.outputs.title }}
477+
include-closed: true
470478
token: ${{ steps.get-auth-token.outputs.token }}
471479

472480
- name: Reopen Project

__tests__/find-project.test.ts

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,27 @@ const title = 'My Title';
2222
const readme = 'README';
2323
const url = 'url';
2424

25+
const mockProject = {
26+
id: projectId,
27+
number: parseInt(projectNumber),
28+
fields: {
29+
totalCount: fieldCount
30+
},
31+
items: {
32+
totalCount: itemCount
33+
},
34+
url,
35+
title,
36+
readme,
37+
shortDescription,
38+
public: true,
39+
closed: false,
40+
owner: {
41+
type: 'Organization' as const,
42+
login: owner
43+
}
44+
};
45+
2546
describe('findProjectAction', () => {
2647
beforeEach(() => {
2748
vi.clearAllMocks();
@@ -91,28 +112,31 @@ describe('findProjectAction', () => {
91112
expect(core.setFailed).toHaveBeenLastCalledWith('42');
92113
});
93114

115+
it('finds closed projects', async () => {
116+
mockGetInput({ owner, title });
117+
mockGetBooleanInput({ 'include-closed': true });
118+
vi.mocked(findProject).mockResolvedValue(mockProject);
119+
120+
await index.findProjectAction();
121+
expect(findProjectActionSpy).toHaveReturned();
122+
123+
expect(findProject).toHaveBeenCalledWith(owner, title, true, '');
124+
});
125+
126+
it('can set limit', async () => {
127+
mockGetInput({ owner, title, limit: '50' });
128+
mockGetBooleanInput({});
129+
vi.mocked(findProject).mockResolvedValue(mockProject);
130+
131+
await index.findProjectAction();
132+
expect(findProjectActionSpy).toHaveReturned();
133+
134+
expect(findProject).toHaveBeenCalledWith(owner, title, false, '50');
135+
});
136+
94137
it('sets output', async () => {
95138
mockGetInput({ owner, title });
96-
vi.mocked(findProject).mockResolvedValue({
97-
id: projectId,
98-
number: parseInt(projectNumber),
99-
fields: {
100-
totalCount: fieldCount
101-
},
102-
items: {
103-
totalCount: itemCount
104-
},
105-
url,
106-
title,
107-
readme,
108-
shortDescription,
109-
public: true,
110-
closed: false,
111-
owner: {
112-
type: 'Organization',
113-
login: owner
114-
}
115-
});
139+
vi.mocked(findProject).mockResolvedValue(mockProject);
116140

117141
await index.findProjectAction();
118142
expect(findProjectActionSpy).toHaveReturned();

__tests__/lib.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,13 +1330,40 @@ describe('lib', () => {
13301330
).resolves.toEqual(null);
13311331
});
13321332

1333+
it('can include closed projects', async () => {
1334+
vi.mocked(execCliCommand).mockResolvedValue(
1335+
JSON.stringify({ projects: [project] })
1336+
);
1337+
await expect(lib.findProject(owner, projectTitle, true)).resolves.toEqual(
1338+
project
1339+
);
1340+
expect(execCliCommand).toHaveBeenCalledWith(
1341+
expect.arrayContaining(['--closed'])
1342+
);
1343+
});
1344+
1345+
it('can set a limit', async () => {
1346+
vi.mocked(execCliCommand).mockResolvedValue(
1347+
JSON.stringify({ projects: [project] })
1348+
);
1349+
await expect(
1350+
lib.findProject(owner, projectTitle, false, '50')
1351+
).resolves.toEqual(project);
1352+
expect(execCliCommand).toHaveBeenCalledWith(
1353+
expect.arrayContaining(['--limit'])
1354+
);
1355+
});
1356+
13331357
it('returns project details', async () => {
13341358
vi.mocked(execCliCommand).mockResolvedValue(
13351359
JSON.stringify({ projects: [project] })
13361360
);
13371361
await expect(lib.findProject(owner, projectTitle)).resolves.toEqual(
13381362
project
13391363
);
1364+
expect(execCliCommand).not.toHaveBeenCalledWith(
1365+
expect.arrayContaining(['--limit'])
1366+
);
13401367
});
13411368
});
13421369

dist/find-project.js

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/github-script/index.js

Lines changed: 9 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

find-project/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Find a GitHub project
1010
|-------------------|----------------------------------------------------|----------|----------------------------------------------|
1111
| `token` | A GitHub access token - either a classic PAT or a GitHub app installation token. | Yes | |
1212
| `owner` | The owner of the project - either an organization or a user. If not provided, it defaults to the repository owner. | No | `${{ github.repository_owner }}` |
13+
| `include-closed` | Include closed projects. | No | `false` |
14+
| `limit` | Maximum number of projects to fetch. | No | 30 |
1315
| `title` | The title of the project to find. | Yes | |
1416
| `fail-if-project-not-found` | Should the action fail if the project is not found | No | `true` |
1517

find-project/action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ inputs:
1717
description: Should the action fail if the project is not found
1818
required: false
1919
default: true
20+
include-closed:
21+
description: Include closed projects
22+
required: false
23+
default: false
24+
limit:
25+
description: Maximum number of projects to fetch
26+
required: false
27+
default: 30
2028

2129
outputs:
2230
id:

src/find-project.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ export async function findProjectAction(): Promise<void> {
1212
const failIfProjectNotFound = core.getBooleanInput(
1313
'fail-if-project-not-found'
1414
);
15+
const includeClosed = core.getBooleanInput('include-closed');
16+
const limit = core.getInput('limit');
1517

16-
const project = await findProject(owner, title);
18+
const project = await findProject(owner, title, includeClosed, limit);
1719

1820
if (!project) {
1921
if (failIfProjectNotFound) core.setFailed(`Project not found: ${title}`);

src/lib.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -901,19 +901,21 @@ export async function editProject(
901901

902902
export async function findProject(
903903
owner: string,
904-
title: string
904+
title: string,
905+
closed = false,
906+
limit?: string
905907
): Promise<ProjectDetails | null> {
906-
// TODO - Pagination
907-
const { projects } = JSON.parse(
908-
await execCliCommand([
909-
'project',
910-
'list',
911-
'--owner',
912-
owner,
913-
'--format',
914-
'json'
915-
])
916-
);
908+
const args = ['project', 'list', '--owner', owner, '--format', 'json'];
909+
910+
if (closed) {
911+
args.push('--closed');
912+
}
913+
914+
if (limit) {
915+
args.push('--limit', limit);
916+
}
917+
918+
const { projects } = JSON.parse(await execCliCommand(args));
917919

918920
for (const project of projects) {
919921
if (project.title === title) {

0 commit comments

Comments
 (0)