Apache Airflow GitHub Provider

2.11.2 · active · verified Thu Apr 16

The `apache-airflow-providers-github` package provides Apache Airflow integrations for interacting with GitHub. It enables users to perform various GitHub operations, such as managing repositories, issues, pull requests, and other Git-related tasks directly from Airflow workflows. This active provider, currently at version 2.11.2, is part of Airflow's modular provider ecosystem, allowing for independent releases and updates from the core Airflow project.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the `GithubOperator` to create a new issue in a specified GitHub repository. Before running, configure an Airflow connection of type 'GitHub' with `conn_id='github_default'`. The 'GitHub Access Token' field should contain a Personal Access Token (PAT) with `repo` scope. Set the `GITHUB_REPO_OWNER` and `GITHUB_REPO_NAME` environment variables (or hardcode for testing) to point to your target repository. Optionally, set `AIRFLOW_GITHUB_ASSIGNEE` to assign the issue.

import os
from datetime import datetime

from airflow.models.dag import DAG
from airflow.providers.github.operators.github import GithubOperator

with DAG(
    dag_id='github_create_issue_example',
    start_date=datetime(2023, 1, 1),
    schedule=None,
    catchup=False,
    tags=['github', 'example', 'issue'],
    doc_md="""### GitHub Create Issue Example
    This DAG demonstrates creating a GitHub issue using the GithubOperator.
    Ensure you have a GitHub connection configured with `conn_id='github_default'`
    and a Personal Access Token with 'repo' scope.

    Environment variables:
    - GITHUB_REPO_OWNER: Owner of the repository (e.g., 'apache')
    - GITHUB_REPO_NAME: Name of the repository (e.g., 'airflow')
    """,
) as dag:
    create_github_issue = GithubOperator(
        task_id='create_github_issue',
        github_conn_id='github_default',
        method_name='create_issue',
        repository_name=f"{os.environ.get('GITHUB_REPO_OWNER', 'test-user')}/{os.environ.get('GITHUB_REPO_NAME', 'test-repo')}",
        title='Airflow created issue from DAG',
        body='This issue was automatically created by an Airflow DAG.',
        assignees=['{AIRFLOW_GITHUB_ASSIGNEE}'], # Optional: Replace with a valid GitHub username for your repo
        labels=['bug', 'airflow-automation'],
        # Optional: You can pass other arguments supported by PyGithub's create_issue method
        # e.g., 'milestone': 1,
    )

view raw JSON →