Notably, this gets us `@actions/github` 6.0.1, which is necessary for `github.context.runAttempt` (so I have also updated `package.json` accordingly). On that note... great job following semver, GitHub! Between this and the non-breaking major version change on `@actions/cache`, I'm starting to feel like nobody on the Actions team understands how software versioning works.
94 lines
3.2 KiB
JavaScript
94 lines
3.2 KiB
JavaScript
// Copyright 2021-2025 Buf Technologies, Inc.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
import { getComments, getDeclarationString, getFeatureOptionStrings, } from "./source-code-info.js";
|
|
import { parentTypes } from "@bufbuild/protobuf/reflect";
|
|
export function createJsDocTextFromDesc(desc) {
|
|
const comments = getComments(desc);
|
|
let text = "";
|
|
if (comments.leading !== undefined) {
|
|
text += comments.leading;
|
|
if (text.endsWith("\n")) {
|
|
text = text.substring(0, text.length - 1);
|
|
}
|
|
}
|
|
if (comments.trailing !== undefined) {
|
|
if (text.length > 0) {
|
|
text += "\n\n";
|
|
}
|
|
text += comments.trailing;
|
|
if (text.endsWith("\n")) {
|
|
text = text.substring(0, text.length - 1);
|
|
}
|
|
}
|
|
if (text.length > 0) {
|
|
text += "\n\n";
|
|
}
|
|
text = text
|
|
.split("\n")
|
|
.map((line) => (line.startsWith(" ") ? line.substring(1) : line))
|
|
.join("\n");
|
|
switch (desc.kind) {
|
|
case "enum_value":
|
|
text += `@generated from enum value: ${getDeclarationString(desc)};`;
|
|
break;
|
|
case "field":
|
|
text += `@generated from field: ${getDeclarationString(desc)};`;
|
|
break;
|
|
case "extension":
|
|
text += `@generated from extension: ${getDeclarationString(desc)};`;
|
|
break;
|
|
case "message":
|
|
case "enum": {
|
|
text += `@generated from ${desc.toString()}`;
|
|
const featureOptions = getFeatureOptionStrings(desc);
|
|
if (featureOptions.length > 0) {
|
|
text += `\n@generated with ${featureOptions.length > 1 ? "options" : "option"} ${featureOptions.join(", ")}`;
|
|
}
|
|
break;
|
|
}
|
|
default:
|
|
text += `@generated from ${desc.toString()}`;
|
|
break;
|
|
}
|
|
let deprecated;
|
|
switch (desc.kind) {
|
|
case "field":
|
|
case "enum_value":
|
|
case "rpc":
|
|
deprecated = desc.deprecated;
|
|
break;
|
|
default:
|
|
deprecated =
|
|
desc.deprecated || parentTypes(desc).some((d) => d.deprecated);
|
|
break;
|
|
}
|
|
if (deprecated) {
|
|
text += "\n@deprecated";
|
|
}
|
|
return text;
|
|
}
|
|
export function formatJsDocBlock(text, indentation) {
|
|
if (text.trim().length == 0) {
|
|
return "";
|
|
}
|
|
let lines = text.split("\n");
|
|
if (lines.length === 0) {
|
|
return "";
|
|
}
|
|
lines = lines.map((l) => l.split("*/").join("*\\/"));
|
|
lines = lines.map((l) => (l.length > 0 ? " " + l : l));
|
|
const i = indentation !== null && indentation !== void 0 ? indentation : "";
|
|
return [`${i}/**\n`, ...lines.map((l) => `${i} *${l}\n`), `${i} */`].join("");
|
|
}
|