Skip to content
Closed
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
16 changes: 14 additions & 2 deletions .github/workflows/campaign-manager.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 84 additions & 40 deletions .github/workflows/docs-quality-maintenance-project67.campaign.lock.yml

Large diffs are not rendered by default.

124 changes: 84 additions & 40 deletions .github/workflows/go-file-size-reduction-project64.campaign.lock.yml

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions .github/workflows/playground-org-project-update-issue.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions actions/setup/js/mark_pull_request_as_ready_for_review.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const { loadAgentOutput } = require("./load_agent_output.cjs");
const { generateFooter } = require("./generate_footer.cjs");
const { sanitizeContent } = require("./sanitize_content.cjs");
const { getErrorMessage } = require("./error_helpers.cjs");

/**
* Generate staged preview for mark-pull-request-as-ready-for-review items
Expand Down Expand Up @@ -69,6 +70,8 @@ async function markPullRequestAsReadyForReview(github, owner, repo, prNumber, re

// Add comment with reason
const workflowName = process.env.GH_AW_WORKFLOW_NAME || "GitHub Agentic Workflow";
const workflowSource = process.env.GH_AW_WORKFLOW_SOURCE || "";
const workflowSourceURL = process.env.GH_AW_WORKFLOW_SOURCE_URL || "";
const runUrl = `${context.serverUrl}/${owner}/${repo}/actions/runs/${context.runId}`;
const workflowSource = process.env.GH_AW_WORKFLOW_SOURCE || "";
const workflowSourceURL = process.env.GH_AW_WORKFLOW_SOURCE_URL || "";
Expand Down
7 changes: 0 additions & 7 deletions actions/setup/js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions actions/setup/js/safe_output_type_validator.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,38 @@ function executeCustomValidation(item, customValidation, lineNum, itemType) {
}
}

if (customValidation === "updateProjectValidTarget") {
const contentType = item.content_type;

if (contentType === "draft_issue") {
const draftTitle = typeof item.draft_title === "string" ? item.draft_title.trim() : "";
if (!draftTitle) {
return {
isValid: false,
error: `Line ${lineNum}: ${itemType} 'draft_title' is required and must be a non-empty string when 'content_type' is 'draft_issue'`,
};
}
return null;
}

const normalize = v => {
if (v === undefined || v === null) return "";
if (typeof v === "number") return Number.isFinite(v) ? String(v) : "";
return String(v).trim();
};

const hasContentNumber = normalize(item.content_number) !== "";
const hasIssue = normalize(item.issue) !== "";
const hasPullRequest = normalize(item.pull_request) !== "";

if (!hasContentNumber && !hasIssue && !hasPullRequest) {
return {
isValid: false,
error: `Line ${lineNum}: ${itemType} requires one of: 'content_number', 'issue', or 'pull_request' (or set 'content_type' to 'draft_issue' with 'draft_title')`,
};
}
}

return null;
}

Expand Down
91 changes: 91 additions & 0 deletions actions/setup/js/safe_output_type_validator.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,28 @@ const SAMPLE_VALIDATION_CONFIG = {
},
},
},
update_project: {
defaultMax: 10,
customValidation: "updateProjectValidTarget",
fields: {
project: {
required: true,
type: "string",
sanitize: true,
maxLength: 512,
pattern: "^https://github\\.com/(orgs|users)/[^/]+/projects/\\d+",
patternError: "must be a full GitHub project URL (e.g., https://github.com/orgs/myorg/projects/42)",
},
campaign_id: { type: "string", sanitize: true, maxLength: 128 },
content_type: { type: "string", enum: ["issue", "pull_request", "draft_issue"] },
content_number: { optionalPositiveInteger: true },
issue: { optionalPositiveInteger: true },
pull_request: { optionalPositiveInteger: true },
draft_title: { type: "string", sanitize: true, maxLength: 256 },
draft_body: { type: "string", sanitize: true, maxLength: 65000 },
fields: { type: "object" },
},
},
};

describe("safe_output_type_validator", () => {
Expand Down Expand Up @@ -396,6 +418,75 @@ describe("safe_output_type_validator", () => {
});
});

describe("custom validation: updateProjectValidTarget", () => {
it("should fail when content_type is draft_issue and draft_title is missing", async () => {
const { validateItem } = await import("./safe_output_type_validator.cjs");

const result = validateItem(
{
type: "update_project",
project: "https://github.com/orgs/acme/projects/42",
content_type: "draft_issue",
},
"update_project",
1
);

expect(result.isValid).toBe(false);
expect(result.error).toContain("draft_title");
});

it("should pass when content_type is draft_issue and draft_title is provided", async () => {
const { validateItem } = await import("./safe_output_type_validator.cjs");

const result = validateItem(
{
type: "update_project",
project: "https://github.com/orgs/acme/projects/42",
content_type: "draft_issue",
draft_title: "Investigate flaky CI",
},
"update_project",
1
);

expect(result.isValid).toBe(true);
});

it("should fail when non-draft item has no target identifiers", async () => {
const { validateItem } = await import("./safe_output_type_validator.cjs");

const result = validateItem(
{
type: "update_project",
project: "https://github.com/orgs/acme/projects/42",
},
"update_project",
1
);

expect(result.isValid).toBe(false);
expect(result.error).toContain("requires one of");
});

it("should pass when non-draft item provides content_number", async () => {
const { validateItem } = await import("./safe_output_type_validator.cjs");

const result = validateItem(
{
type: "update_project",
project: "https://github.com/orgs/acme/projects/42",
content_type: "issue",
content_number: 123,
},
"update_project",
1
);

expect(result.isValid).toBe(true);
});
});

describe("enum validation", () => {
it("should validate enum values (case-insensitive)", async () => {
const { validateItem } = await import("./safe_output_type_validator.cjs");
Expand Down
55 changes: 41 additions & 14 deletions actions/setup/js/update_project.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,37 @@
const { loadAgentOutput } = require("./load_agent_output.cjs");
const { getErrorMessage } = require("./error_helpers.cjs");

/**
* Normalize a field name for matching against existing Project field names.
* This intentionally treats punctuation (like "/") as whitespace so that
* keys like "worker_workflow" can match field names like "Worker/Workflow".
*
* @param {unknown} name
* @returns {string}
*/
function normalizeFieldNameForComparison(name) {
return String(name || "")
.toLowerCase()
.replace(/[^a-z0-9]+/g, " ")
.trim();
}

/**
* Convert a key-like field name (snake_case, kebab-case, etc) into a display
* name suitable for creating/renaming Project fields.
*
* @param {unknown} fieldKey
* @returns {string}
*/
function toProjectFieldDisplayName(fieldKey) {
return String(fieldKey || "")
.trim()
.split(/[^a-zA-Z0-9]+/)
.filter(Boolean)
.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
.join(" ");
}

/**
* Log detailed GraphQL error information
* @param {Error & { errors?: Array<{ type?: string, message: string, path?: unknown, locations?: unknown }>, request?: unknown, data?: unknown }} error - GraphQL error
Expand Down Expand Up @@ -379,19 +410,17 @@ async function updateProject(output) {
)
).node.fields.nodes;
for (const [fieldName, fieldValue] of Object.entries(fieldsToUpdate)) {
const normalizedFieldName = fieldName
.split(/[\s_-]+/)
.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
.join(" ");
const wantedFieldName = normalizeFieldNameForComparison(fieldName);
const displayFieldName = toProjectFieldDisplayName(fieldName);
let valueToSet,
field = projectFields.find(f => f.name.toLowerCase() === normalizedFieldName.toLowerCase());
field = projectFields.find(f => normalizeFieldNameForComparison(f.name) === wantedFieldName);
if (!field)
if ("classification" === fieldName.toLowerCase() || ("string" == typeof fieldValue && fieldValue.includes("|")))
try {
field = (
await github.graphql(
"mutation($projectId: ID!, $name: String!, $dataType: ProjectV2CustomFieldType!) {\n createProjectV2Field(input: {\n projectId: $projectId,\n name: $name,\n dataType: $dataType\n }) {\n projectV2Field {\n ... on ProjectV2Field {\n id\n name\n }\n ... on ProjectV2SingleSelectField {\n id\n name\n options { id name }\n }\n }\n }\n }",
{ projectId, name: normalizedFieldName, dataType: "TEXT" }
{ projectId, name: displayFieldName, dataType: "TEXT" }
)
).createProjectV2Field.projectV2Field;
} catch (createError) {
Expand All @@ -403,7 +432,7 @@ async function updateProject(output) {
field = (
await github.graphql(
"mutation($projectId: ID!, $name: String!, $dataType: ProjectV2CustomFieldType!, $options: [ProjectV2SingleSelectFieldOptionInput!]!) {\n createProjectV2Field(input: {\n projectId: $projectId,\n name: $name,\n dataType: $dataType,\n singleSelectOptions: $options\n }) {\n projectV2Field {\n ... on ProjectV2SingleSelectField {\n id\n name\n options { id name }\n }\n ... on ProjectV2Field {\n id\n name\n }\n }\n }\n }",
{ projectId, name: normalizedFieldName, dataType: "SINGLE_SELECT", options: [{ name: String(fieldValue), description: "", color: "GRAY" }] }
{ projectId, name: displayFieldName, dataType: "SINGLE_SELECT", options: [{ name: String(fieldValue), description: "", color: "GRAY" }] }
)
).createProjectV2Field.projectV2Field;
} catch (createError) {
Expand Down Expand Up @@ -501,19 +530,17 @@ async function updateProject(output) {
)
).node.fields.nodes;
for (const [fieldName, fieldValue] of Object.entries(fieldsToUpdate)) {
const normalizedFieldName = fieldName
.split(/[\s_-]+/)
.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
.join(" ");
const wantedFieldName = normalizeFieldNameForComparison(fieldName);
const displayFieldName = toProjectFieldDisplayName(fieldName);
let valueToSet,
field = projectFields.find(f => f.name.toLowerCase() === normalizedFieldName.toLowerCase());
field = projectFields.find(f => normalizeFieldNameForComparison(f.name) === wantedFieldName);
if (!field)
if ("classification" === fieldName.toLowerCase() || ("string" == typeof fieldValue && fieldValue.includes("|")))
try {
field = (
await github.graphql(
"mutation($projectId: ID!, $name: String!, $dataType: ProjectV2CustomFieldType!) {\n createProjectV2Field(input: {\n projectId: $projectId,\n name: $name,\n dataType: $dataType\n }) {\n projectV2Field {\n ... on ProjectV2Field {\n id\n name\n }\n ... on ProjectV2SingleSelectField {\n id\n name\n options { id name }\n }\n }\n }\n }",
{ projectId, name: normalizedFieldName, dataType: "TEXT" }
{ projectId, name: displayFieldName, dataType: "TEXT" }
)
).createProjectV2Field.projectV2Field;
} catch (createError) {
Expand All @@ -525,7 +552,7 @@ async function updateProject(output) {
field = (
await github.graphql(
"mutation($projectId: ID!, $name: String!, $dataType: ProjectV2CustomFieldType!, $options: [ProjectV2SingleSelectFieldOptionInput!]!) {\n createProjectV2Field(input: {\n projectId: $projectId,\n name: $name,\n dataType: $dataType,\n singleSelectOptions: $options\n }) {\n projectV2Field {\n ... on ProjectV2SingleSelectField {\n id\n name\n options { id name }\n }\n ... on ProjectV2Field {\n id\n name\n }\n }\n }\n }",
{ projectId, name: normalizedFieldName, dataType: "SINGLE_SELECT", options: [{ name: String(fieldValue), description: "", color: "GRAY" }] }
{ projectId, name: displayFieldName, dataType: "SINGLE_SELECT", options: [{ name: String(fieldValue), description: "", color: "GRAY" }] }
)
).createProjectV2Field.projectV2Field;
} catch (createError) {
Expand Down
Loading
Loading