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

[GIT] Ignore warning, error message #252

Merged
merged 6 commits into from
Jun 4, 2021
Merged

[GIT] Ignore warning, error message #252

merged 6 commits into from
Jun 4, 2021

Conversation

seonggwonyoon
Copy link
Contributor

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Bug fix

What is the current behavior? (You can also link to an open issue here)
withfig/fig#107

What is the new behavior (if this is a feature change)?

Additional info:

@withfig-bot
Copy link
Collaborator

withfig-bot commented Jun 2, 2021

Overview

dev/git.ts:

Info:

Script:
git log --oneline
postProcess(function):

 function (out) {
      const output = filterMessages(out);

      if (output.startsWith("fatal:")) {
        return [];
      }

      return output.split("\n").map((line) => {
        return {
          name: line.substring(0, 7),
          icon: "fig:https://icon?type=node",
          description: line.substring(7),
        };
      });
    }

Script:
git stash list
postProcess(function):

 function (out) {
      const output = filterMessages(out);

      if (output.startsWith("fatal:")) {
        return [];
      }

      return output.split("\n").map((file) => {
        return {
          name: file.split(":")[2],
          insertValue: file.split(":")[0],
          icon: `fig:https://icon?type=node`,
        };
      });
    }

Script:
git diff --cached --name-only
postProcess(function):

 function (out) {
      const output = filterMessages(out);

      if (output.startsWith("fatal:")) {
        return [];
      }

      return output.split("\n").map((file) => {
        return {
          name: file,
          insertValue: "-- " + file,
          icon: `fig:https://icon?type=file`,
          description: "staged file",
        };
      });
    }

Script:
git branch --no-color
postProcess(function):

 function (out) {
      const output = filterMessages(out);

      if (output.startsWith("fatal:")) {
        return [];
      }

      return output.split("\n").map((elm) => {
        // current branch
        if (elm.includes("*")) {
          return {
            name: elm.replace("*", "").trim(),
            description: "current branch",
            icon: "⭐️",
            // priority: 100,
          };
        }

        return {
          name: elm.trim(),
          description: "branch",
          icon: "fig:https://icon?type=git",
        };
      });
    }

Script:
git remote -v
postProcess(function):

 function (out) {
      const remoteURLs = out.split("\n").reduce((dict, line) => {
        const pair = line.split("\t");
        const remote = pair[0];
        console.log(remote, pair);
        const url = pair[1].split(" ")[0];

        dict[remote] = url;
        return dict;
      }, {});

      return Object.keys(remoteURLs).map((remote) => {
        const url = remoteURLs[remote];
        let icon = "box";
        if (url.includes("github.com")) {
          icon = "github";
        }

        if (url.includes("gitlab.com")) {
          icon = "gitlab";
        }

        if (url.includes("heroku.com")) {
          icon = "heroku";
        }
        return {
          name: remote,
          icon: `fig:https://icon?type=${icon}`,
          description: "remote",
        };
      });
    }

Single Scripts:

  • git tag --list
  • git status --short
  • git diff --name-only --cached
  • git diff --name-only

@withfig-bot
Copy link
Collaborator

Hello @seonggwonyoon,
thank you very much for creating a Pull Request!
Here is a small checklist to get this PR merged as quickly as possible:

  • Do all subcommands / options which take arguments have the arg property (arg: {})?
  • Are all options modular? E.g. a -u -x instead of -aux
  • Have all other checks passed?

Please add a 👍 as a reaction to this comment to show that you read this.

@QuiiBz
Copy link
Contributor

QuiiBz commented Jun 2, 2021

Hi, thanks a lot for your first contribution! Based on Matt's comment (withfig/fig#107 (comment)), shouldn't it filter out anything starting with error too, not only warning?

@seonggwonyoon
Copy link
Contributor Author

Hi, thanks a lot for your first contribution! Based on Matt's comment (withfig/fig#107 (comment)), shouldn't it filter out anything starting with error too, not only warning?

Thank you @QuiiBz
I missed error option! just added.

@seonggwonyoon seonggwonyoon changed the title [GIT] Ignore warning message [GIT] Ignore warning, error message Jun 2, 2021
Copy link
Contributor

@QuiiBz QuiiBz left a comment

Choose a reason for hiding this comment

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

I think we can simplify this and create a top-level function to avoid duplication. Something like this (not tested):

const filter = (out: string): string => {
  return (out.startsWith("warning:") || out.startsWith("error:"))
    ? out.split("\n").slice(1).join("\n")
    : out;
}

So we will only call filter this way:

out = filter(out);

@seonggwonyoon
Copy link
Contributor Author

I think we can simplify this and create a top-level function to avoid duplication. Something like this (not tested):

const filter = (out: string): string => {
  return (out.startsWith("warning:") || out.startsWith("error:"))
    ? out.split("\n").slice(1).join("\n")
    : out;
}

So we will only call filter this way:

out = filter(out);

As you said, I applied the filter function!

@seonggwonyoon seonggwonyoon requested a review from QuiiBz June 2, 2021 13:41
Copy link
Contributor

@QuiiBz QuiiBz left a comment

Choose a reason for hiding this comment

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

That's cleaner!

dev/git.ts Outdated Show resolved Hide resolved
@seonggwonyoon seonggwonyoon requested a review from cstrnt June 3, 2021 03:58
dev/git.ts Outdated Show resolved Hide resolved
dev/git.ts Outdated Show resolved Hide resolved
dev/git.ts Outdated Show resolved Hide resolved
dev/git.ts Outdated Show resolved Hide resolved
@seonggwonyoon seonggwonyoon requested a review from cstrnt June 4, 2021 05:55
@seonggwonyoon seonggwonyoon requested a review from QuiiBz June 4, 2021 05:59
Copy link
Contributor

@QuiiBz QuiiBz left a comment

Choose a reason for hiding this comment

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

LGTM

@cstrnt
Copy link
Contributor

cstrnt commented Jun 4, 2021

Hey sorry to be annoying, but could you please run npm run lint:fix in order to to fix the styling :) After this is done, we will merge the PR 😊

@seonggwonyoon
Copy link
Contributor Author

Hey sorry to be annoying, but could you please run npm run lint:fix in order to to fix the styling :) After this is done, we will merge the PR 😊

Fixed it. Thanks @cstrnt

@cstrnt cstrnt merged commit 457b3fe into withfig:master Jun 4, 2021
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.

4 participants