Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populate pull request commit details and update packages #13

Merged
merged 7 commits into from
Dec 4, 2024

Conversation

terryknowlton
Copy link
Collaborator

Enhancements to include CI-* details from pull_request event triggers. Also updates dependencies to latest versions

Copy link
Owner

@twistedpair twistedpair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TY, @terryknowlton .

Few Qs.

action.yml Outdated Show resolved Hide resolved
src/index.ts Show resolved Hide resolved
src/index.ts Show resolved Hide resolved
src/index.ts Show resolved Hide resolved
const head = pullRequestEvent.head;
const user = head.user;
setVariable(EnvironmentVariables.CI_COMMIT_ID, head.sha);
setVariable(EnvironmentVariables.CI_COMMITTER_USERNAME, user.login);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a diff b/t username for push and login here for the PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, unfortunately the models are different for the various event types.

PushEvent.head_commit gives us a nullable Commit object which has an author: Committer object (there is also a PushEvent.pusher: Committer that I'm guessing has the same Committer object). The committer object then has

/**
 * For pushes where `after` is or points to a commit object, an expanded representation of that commit. For pushes where `after` refers to an annotated tag object, an expanded representation of the commit pointed to by the annotated tag.
 */
export interface PushEvent {
  ...
  head_commit: Commit | null;
  ...
}

export interface Commit {
  ...
  author: Committer
  ...
}


export interface Committer {
  /**
   * The git author's name.
   */
  name: string;
  /**
   * The git author's email address.
   */
  email: string | null;
  date?: string;
  username?: string;
}

PullRequest does not have any Commit object except for an array of them to list all commits on the PR and a User object with the triggering user for the latest commit. The PullRequest.head field provides an object with some of the commit info like the sha and the user information but not the message.

export interface PullRequest {
  ...
  user: User;
  head: {
    label: string;
    ref: string;
    sha: string;
    user: User;
    repo: Repository | null;
  };
  ... 
}

export interface User {
  login: string;
  id: number;
  node_id: string;
  name?: string;
  email?: string | null;
  avatar_url: string;
  gravatar_id: string;
  url: string;
  html_url: string;
  followers_url: string;
  following_url: string;
  gists_url: string;
  starred_url: string;
  subscriptions_url: string;
  organizations_url: string;
  repos_url: string;
  events_url: string;
  received_events_url: string;
  type: "Bot" | "User" | "Organization";
  site_admin: boolean;
}

Copy link
Owner

@twistedpair twistedpair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @terryknowlton ❤️

One more ask: can we explain this extra functionality in the README.md? (e.g. overall and for that specific field).

@terryknowlton terryknowlton changed the title Populate pull request commit details and updatee packages Populate pull request commit details and update packages Dec 4, 2024
@terryknowlton terryknowlton merged commit 5aaf312 into main Dec 4, 2024
1 check passed
@terryknowlton terryknowlton deleted the populate-pr-event-details branch December 4, 2024 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants