Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ The action provides only one output:

The action supports the following field data types:

| Field Type | GraphQL Type | Description |
| :-----------: | :--------------: | :---------------------------------------------: |
| Text | [String][String] | The literal string in the field |
| Number | [Float][Float] | The string representation of a number |
| Date | [Date][Date] | The date in the YYYY-MM-DD format |
| Single Select | [String][String] | The name of the option (must be an exact match) |
| Field Type | GraphQL Type | Description |
| :-----------: | :--------------: | :------------------------------------------------: |
| Text | [String][String] | The literal string in the field |
| Number | [Float][Float] | The string representation of a number |
| Date | [Date][Date] | The date in the YYYY-MM-DD format |
| Single Select | [String][String] | The name of the option (must be an exact match) |
| Iteration | [String][String] | The name of the iteration (must be an exact match) |

[String]: https://docs.github.com/en/graphql/reference/scalars#string
[Float]: https://docs.github.com/en/graphql/reference/scalars#float
Expand Down
8 changes: 4 additions & 4 deletions build/index.js

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions build/query/getField.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ query getField($owner: String!, $projectNumber: Int!, $fieldName: String!) {
name
}
}
... on ProjectV2IterationField {
id
configuration {
iterations {
id
title
}
completedIterations {
id
title
}
}
}
}
}
}
Expand All @@ -29,6 +42,19 @@ query getField($owner: String!, $projectNumber: Int!, $fieldName: String!) {
name
}
}
... on ProjectV2IterationField {
id
configuration {
iterations {
id
title
}
completedIterations {
id
title
}
}
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions build/query/getFieldValues.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ query getFieldValues($resourceUrl: URI!) {
... on ProjectV2ItemFieldNumberValue {
number
}
... on ProjectV2ItemFieldIterationValue {
title
}
}
}
}
Expand Down Expand Up @@ -68,6 +71,9 @@ query getFieldValues($resourceUrl: URI!) {
... on ProjectV2ItemFieldNumberValue {
number
}
... on ProjectV2ItemFieldIterationValue {
title
}
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type FieldsResult = Record<
string,
| {
value: string | number | undefined;
type: 'TEXT' | 'SINGLE_SELECT' | 'NUMBER' | 'DATE';
type: 'TEXT' | 'SINGLE_SELECT' | 'NUMBER' | 'DATE' | 'ITERATION';
id: string;
unsupported?: false;
}
Expand Down Expand Up @@ -154,6 +154,13 @@ export class Octo {
id: node.field.id,
};
break;
case 'ITERATION':
result[node.field.name] = {
value: node.title,
type: node.field.dataType,
id: node.field.id,
};
break;
default:
result[node.field.name] = {
id: node.field.id,
Expand Down Expand Up @@ -230,6 +237,7 @@ export class Octo {
}
| {date: string}
| {singleSelectOptionId: string}
| {iterationId: string}
) {
await this._request('setItemFieldValue', {
projectId,
Expand Down
17 changes: 16 additions & 1 deletion src/api/responseTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,21 @@ export interface getField {
}
| {
id: string;
dataType: Exclude<FieldDataType, 'SINGLE_SELECT'>;
dataType: 'ITERATION';
configuration: {
iterations: {
id: string;
title: string;
}[];
completedIterations: {
id: string;
title: string;
}[];
};
}
| {
id: string;
dataType: Exclude<FieldDataType, 'SINGLE_SELECT' | 'ITERATION'>;
};
};
};
Expand Down Expand Up @@ -42,6 +56,7 @@ export interface getFieldValues {
name?: string;
number?: number;
date?: string;
title?: string;
}
)[];
};
Expand Down
19 changes: 18 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const supportedDataTypes = [
'SINGLE_SELECT',
'NUMBER',
'DATE',
'ITERATION',
] as FieldDataType[];

(async () => {
Expand Down Expand Up @@ -126,6 +127,18 @@ const supportedDataTypes = [
);
singleSelectOptionId = option.id;
}
let iterationId: string;
if (field.dataType === 'ITERATION') {
const allIterations = field.configuration.iterations.concat(
field.configuration.completedIterations
);
const iteration = allIterations.find(o => o.title === value);
if (!iteration)
throw new Error(
`Field ${field.name} has data type ${field.dataType}, but the value is not a valid iteration.`
);
iterationId = iteration.id;
}
const newValue:
| Parameters<(typeof octokit)['setFieldValue']>[3]
| undefined =
Expand All @@ -145,7 +158,11 @@ const supportedDataTypes = [
? {
date: value,
}
: undefined;
: field.dataType === 'ITERATION'
? {
iterationId: iterationId!,
}
: undefined;
if (!newValue)
throw new Error(
`Field ${field.name} has an unsupported data type: ${field.dataType}. This should never happen.`
Expand Down
26 changes: 26 additions & 0 deletions src/query/getField.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ query getField($owner: String!, $projectNumber: Int!, $fieldName: String!) {
name
}
}
... on ProjectV2IterationField {
id
configuration {
iterations {
id
title
}
completedIterations {
id
title
}
}
}
}
}
}
Expand All @@ -29,6 +42,19 @@ query getField($owner: String!, $projectNumber: Int!, $fieldName: String!) {
name
}
}
... on ProjectV2IterationField {
id
configuration {
iterations {
id
title
}
completedIterations {
id
title
}
}
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/query/getFieldValues.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ query getFieldValues($resourceUrl: URI!) {
... on ProjectV2ItemFieldNumberValue {
number
}
... on ProjectV2ItemFieldIterationValue {
title
}
}
}
}
Expand Down Expand Up @@ -68,6 +71,9 @@ query getFieldValues($resourceUrl: URI!) {
... on ProjectV2ItemFieldNumberValue {
number
}
... on ProjectV2ItemFieldIterationValue {
title
}
}
}
}
Expand Down