from urllib.parse import urlencode
from typing import OrderedDict


def make_pr_link(url, project, slug, from_branch, to_branch):
    """Generates a URL that can be used to create a PR"""

    if "github.com" in url:
        result = "{url}/{organization}/{repo_name}/compare/{to_branch}...{from_branch}".format(
            url=url,
            organization=project,
            repo_name=slug,
            from_branch=from_branch,
            to_branch=to_branch,
        )
    else:
        base_url = "{url}/projects/{project}/repos/{slug}/compare/commits?".format(
            url=url, project=project, slug=slug
        )
        result = base_url + urlencode(
            OrderedDict([("sourceBranch", from_branch), ("targetBranch", to_branch)])
        )

    return result