How to use the ghstack.diff.PullRequestResolved function in ghstack

To help you get started, we’ve selected a few ghstack examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ezyang / ghstack / ghstack / submit.py View on Github external
r = self.github.post(
            "repos/{owner}/{repo}/pulls"
            .format(owner=self.repo_owner, repo=self.repo_name),
            title=title,
            head=branch_head(self.username, ghnum),
            base=branch_base(self.username, ghnum),
            body=pr_body,
            maintainer_can_modify=True,
        )
        number = r['number']

        logging.info("Opened PR #{}".format(number))

        # Update the commit message of the local diff with metadata
        # so we can correlate these later
        pull_request_resolved = ghstack.diff.PullRequestResolved(
            owner=self.repo_owner, repo=self.repo_name, number=number)
        commit_msg = ("{commit_msg}\n\n"
                      "ghstack-source-id: {sourceid}\n"
                      "Pull Request resolved: "
                      "https://github.com/{owner}/{repo}/pull/{number}"
                      .format(commit_msg=commit.summary.rstrip(),
                              owner=self.repo_owner,
                              repo=self.repo_name,
                              number=number,
                              sourceid=commit.source_id))

        # TODO: Try harder to preserve the old author/commit
        # information (is it really necessary? Check what
        # --amend does...)
        new_orig = GitCommitHash(self.sh.git(
            "commit-tree",
github ezyang / ghstack / ghstack / submit.py View on Github external
STACK_HEADER = "Stack from [ghstack](https://github.com/ezyang/ghstack)"


@dataclass
class DiffWithGitHubMetadata:
    diff: ghstack.diff.Diff
    number: GitHubNumber
    # Really ought not to be optional, but for BC reasons it might be
    remote_source_id: Optional[str]
    title: str
    body: str
    closed: bool
    ghnum: GhNumber
    pull_request_resolved: ghstack.diff.PullRequestResolved


def main(msg: Optional[str],
         username: str,
         github: ghstack.github.GitHubEndpoint,
         update_fields: bool = False,
         sh: Optional[ghstack.shell.Shell] = None,
         stack_header: str = STACK_HEADER,
         repo_owner: Optional[str] = None,
         repo_name: Optional[str] = None,
         short: bool = False,
         force: bool = False,
         no_skip: bool = False,
         ) -> List[DiffMeta]:

    if sh is None:
github ezyang / ghstack / ghstack / git.py View on Github external
def convert(h: CommitHeader) -> ghstack.diff.Diff:
        parents = h.parents()
        if len(parents) != 1:
            raise RuntimeError(
                "The commit {} has {} parents, which makes my head explode.  "
                "`git rebase -i` your diffs into a stack, then try again."
                .format(h.commit_id(), len(parents)))
        return ghstack.diff.Diff(
            title=h.title(),
            summary=h.commit_msg(),
            oid=h.commit_id(),
            source_id=h.tree(),
            pull_request_resolved=ghstack.diff.PullRequestResolved.search(h.raw_header),
            patch=GitPatch(h)
        )
github ezyang / ghstack / ghstack / diff.py View on Github external
# Unique identifier representing the commit in question (may be a
    # Git/Mercurial commit hash; the important thing is that it can be
    # used as a unique identifier.)
    oid: str

    # Unique identifier representing the commit in question, but it
    # is *invariant* to changes in commit message / summary.  In Git,
    # a valid identifier would be the tree hash of the commit (rather
    # than the commit hash itself); in Phabricator it could be the
    # version of the diff.
    source_id: str

    # The contents of 'Pull Request resolved'.  This is None for
    # diffs that haven't been submitted by ghstack.  For BC reasons,
    # this also accepts gh-metadata.
    pull_request_resolved: Optional[PullRequestResolved]

    # Function which applies this diff to the input tree, producing a
    # new tree.  There will only be two implementations of this:
    #
    #   - Git: A no-op function, which asserts that GitTreeHash is some
    #     known tree and then returns a fixed GitTreeHash (since we
    #     already know exactly what tree we want.)
    #
    #   - Hg: A function which applies some patch to the git tree
    #     giving you the result.
    #
    # This function is provided a shell whose cwd is the Git repository
    # that the tree hashes live in.
    #
    # NB: I could have alternately represented this as
    # Optional[GitTreeHash] + Optional[UnifiedDiff] but that would
github ezyang / ghstack / ghstack / diff.py View on Github external
def search(s: str) -> Optional['PullRequestResolved']:
        m = RE_PULL_REQUEST_RESOLVED.search(s)
        if m is not None:
            return PullRequestResolved(
                owner=m.group("owner"),
                repo=m.group("repo"),
                number=GitHubNumber(int(m.group("number"))),
            )
        m = RE_GH_METADATA.search(s)
        if m is not None:
            return PullRequestResolved(
                owner=m.group("owner"),
                repo=m.group("repo"),
                number=GitHubNumber(int(m.group("number"))),
            )
        return None