JonasPammer / cookiecutter-ansible-role

An awesome CookieCutter for my ansible roles.
MIT License
1 stars 3 forks source link

fix issue-label-manager-action #9

Closed JonasPammer closed 2 years ago

JonasPammer commented 2 years ago

https://github.com/JonasPammer/ansible-role-shellcheck/runs/6191546606?check_suite_focus=true

maybe create own new action?

JonasPammer commented 2 years ago

as seen here, it's a problem introduced in https://github.com/JonasPammer/ansible-role-shellcheck/runs/6191627456?check_suite_focus=true because this action is almost stale-alike and has no tests i'm going to write my own first action

JonasPammer commented 2 years ago

Midway through making my own issue-label-manager-action with near same functionality of lannonbr's one from my cookiecutter i just found out about https://github.com/crazy-max/ghaction-github-labeler and it ticks all the boxes

though i see the time not as wasted - https://github.com/JonasPammer/cookiecutter-github-action-typescript/ i learned and got-into (again) on npm, jest, typescript, CI/CD workflows of a nodejs project, github actions, ... it was also really interesting to forst through the source of octokit and analyze/see how they did types (its crazy how they did it)


snippets of my code for memorian purposes: (full version way-back-machined at https://web.archive.org/web/20220719103720/https://github.com/JonasPammer/issue-label-manager-action/commit/35382d4a132d16b7a74082a28ace5ef5f30dbcd3)

/**
 * Label Definition as returned by API
 * https://docs.github.com/en/rest/issues/labels#list-labels-for-a-repository
 */
export type Label =
  RestEndpointMethodTypes["issues"]["listLabelsForRepo"]["response"]["data"][0];

/**
 * Label Input Definition as per this roles Documentation
 */
export type LabelDefinition = {
  name: Label["name"];
  color: Label["color"];
  description: Label["description"];
};

/**
 * Used by {@link diffLabels}
 */
export type LabelDiff = {
  type: "create" | "update" | "delete";
  label: LabelDefinition | Label;
};

export async function getCurrentLabels(
  api: Readonly<OctokitApi>
): Promise<Label[]> {
describe("getInputList", () => {
  ....
  it("test diffLabel recognizes description-only change", async () => {
    const oldLabel: Readonly<Label> = {
      id: 0,
      node_id: "0",
      url: "undefined",
      name: "mylabel",
      description: "Description Old",
      color: "000000",
      default: false,
    };
    const newLabel: LabelDefinition = {
      name: oldLabel.name,
      description: "Description NEW",
      color: oldLabel.color,
    };
    let result: LabelDiff[] = diffLabels([oldLabel], [newLabel]);
    expect(result.length).toBe(1);
    expect(result[0].type).toBe("update");

    // Check if casing-only difference is recognized:
    // @ts-ignore: description can not be null here
    newLabel.description = oldLabel.description.toLowerCase;
    result = diffLabels([oldLabel], [newLabel]);
    expect(result.length).toBe(1);
    expect(result[0].type).toBe("update");
  });
  ....
JonasPammer commented 2 years ago

done as per https://github.com/JonasPammer/cookiecutter-ansible-role/compare/1f2873c63d4e3717cb327386cdef4ea0958f1d40...8965100908632d272e4830b5b4289224304c71d2