DEV Community

Tue
Tue

Posted on

The end of Hacktoberfest

Finally, I've got my 4th pull request merged.

The issue:

I was looking some good issues in repos that I have starred and I found the issue Update CreateEvent to deal with repository creation.

This is the live feed of the website and it failed to display the message whenever someone would create a new repo in the organization.
Website ucla opensource screenshot

Coming up with a solution

Let's take a look at how the front-end component deals with the REST endpoint

    case 'CreateEvent':
    case 'DeleteEvent': {
      const target = payload?.ref;
      const targetType = payload?.ref_type;
      const action = type === 'CreateEvent'? 'created' : 'deleted';
      if (!targetType || !target) {
        return unknown;
      }
      return <span>{action} {targetType} <code>{target}</code> in</span>;
    }
Enter fullscreen mode Exit fullscreen mode

and the data returned by the api

{
    "id": "18549674018",
    "type": "CreateEvent",
    "actor": {
      "id": 65370631,
      "login": "matthewcn56",
      "display_login": "matthewcn56",
      "gravatar_id": "",
      "url": "https://api.github.com/users/matthewcn56",
      "avatar_url": "https://avatars.githubusercontent.com/u/65370631?"
    },
    "repo": {
      "id": 419984626,
      "name": "uclaacm/status-check",
      "url": "https://api.github.com/repos/uclaacm/status-check"
    },
    "payload": {
      "ref": null,
      "ref_type": "repository",
      "master_branch": "main",
      "description": "Check the health/status of ACM's various websites/deployments!",
      "pusher_type": "user"
    },
Enter fullscreen mode Exit fullscreen mode

Since ref is null when a user creates a new repo, the code returns the default message unknown. Therefore, adding a condition should fix it.

      if (!target) {
        return <span>{action} the {targetType} </span>;
      }
      if (!targetType) {
        return unknown;
      }
Enter fullscreen mode Exit fullscreen mode

Reflection

Though the issue wasn't hard to solve, I found it more valuable getting to know the project's workflow. I got to learn about husky, pre-commit hooks and how to make sure code linting has no error before passing the PR tests as well as GitHub API.

Top comments (0)