Ejemplo n.º 1
0
def test_processes_issues(make_authorized_session, list_org_issues,
                          process_issue):
    pr1 = {
        "base": {
            "ref": "abc123",
            "repo": {
                "full_name": "googleapis/java-asset"
            }
        },
        "pull_request": {
            "html_url": "https://github.com/googleapis/java-asset"
        },
        "title": "chore: release 1.2.3",
    }
    pr2 = {
        "base": {
            "ref": "def456",
            "repo": {
                "full_name": "googleapis/nodejs-container"
            }
        },
        "pull_request": {
            "html_url": "https://github.com/nodejs/java-container"
        },
        "title": "chore: release 1.0.0",
    }
    list_org_issues.side_effect = [[pr1, pr2]]
    tag.main("github-token", "kokoro-credentials")
    list_org_issues.assert_any_call(org="googleapis",
                                    state="closed",
                                    labels="autorelease: pending")
    list_org_issues.assert_any_call(org="GoogleCloudPlatform",
                                    state="closed",
                                    labels="autorelease: pending")
    assert process_issue.call_count == 2
Ejemplo n.º 2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--report")
    parser.add_argument("--github-token",
                        default=os.environ.get("GITHUB_TOKEN"))
    parser.add_argument(
        "--kokoro-credentials",
        default=os.environ.get("AUTORELEASE_KOKORO_CREDENTIALS"))
    parser.add_argument("command")

    args = parser.parse_args()

    args.github_token = _determine_github_token(args.github_token)

    if args.command == "tag":
        report = tag.main(args.github_token, args.kokoro_credentials)

        if args.report:
            report.write(args.report)

        if report.failures:
            sys.exit(2)
        else:
            return
    else:
        print(f"Unknown command {args.command}.")
        sys.exit(1)
Ejemplo n.º 3
0
def test_no_issues(make_authorized_session, list_org_issues, process_issue):
    list_org_issues.return_value = []

    tag.main("github-token", "kokoro-credentials")
    make_authorized_session.assert_called_once()
    process_issue.assert_not_called()
Ejemplo n.º 4
0
def test_respects_allowlist(make_authorized_session, list_org_issues,
                            run_releasetool_tag):
    pr1 = {
        "base": {
            "ref": "abc123",
            "repo": {
                "full_name": "googleapis/java-asset"
            }
        },
        "pull_request": {
            "url":
            "https://api.github.com/repos/googleapis/java-asset/pull/123",
            "html_url": "https://github.com/googleapis/java-asset",
        },
        "title": "chore: release 1.2.3",
    }
    pr2 = {
        "base": {
            "ref": "def456",
            "repo": {
                "full_name": "googleapis/nodejs-container"
            }
        },
        "pull_request": {
            "url":
            "https://api.github.com/repos/googleapis/nodejs-container/pull/234",
            "html_url": "https://github.com/nodejs/nodejs-container",
        },
        "title": "chore: release 1.0.0",
    }
    list_org_issues.side_effect = [[pr1, pr2]]
    with requests_mock.Mocker() as m:
        m.get(
            "https://api.github.com/repos/googleapis/java-asset/pull/123",
            json={
                "merged_at": "2021-01-01T09:00:00.000Z",
                "base": {
                    "repo": {
                        "full_name": "googleapis/java-asset"
                    }
                },
            },
        )
        m.get(
            "https://api.github.com/repos/googleapis/nodejs-container/pull/234",
            json={
                "merged_at": "2021-01-01T09:00:00.000Z",
                "base": {
                    "repo": {
                        "full_name": "googleapis/nodejs-container"
                    }
                },
            },
        )
        tag.main("github-token", "kokoro-credentials")
    list_org_issues.assert_any_call(org="googleapis",
                                    state="closed",
                                    labels="autorelease: pending")
    list_org_issues.assert_any_call(org="GoogleCloudPlatform",
                                    state="closed",
                                    labels="autorelease: pending")
    assert run_releasetool_tag.call_count == 1