diff --git a/docs/github-integration.md b/docs/github-integration.md index fd84322..f748bd2 100644 --- a/docs/github-integration.md +++ b/docs/github-integration.md @@ -1,77 +1,6 @@ # GitHub Integration -STRUCT can seamlessly integrate with GitHub to automate the generation of project structures across repositories. This documentation explains how to set up and use the GitHub trigger script. - -## GitHub Trigger Script - -The `github-trigger.py` script is a utility designed to trigger the `run-struct` workflow for all private repositories in a GitHub organization that meet specific criteria. This script is particularly useful for automating tasks across multiple repositories. - -### Features - -- Filters repositories by a specific topic (e.g., `struct-enabled`). -- Checks for the existence of a `.struct.yaml` file in the repository's default branch. -- Verifies the presence of the `run-struct` workflow file in `.github/workflows/`. -- Triggers the workflow dispatch event for eligible repositories. - -### Usage - -To use the script, ensure you have the following prerequisites: - -1. A valid GitHub Personal Access Token with the necessary permissions (set as the `GITHUB_TOKEN` environment variable). -2. The `PyGithub` library installed (`pip install PyGithub`). - -Run the script with the following command: - -```sh -python3 scripts/github-trigger.py -``` - -#### Arguments - -- ``: The name of the GitHub organization. -- ``: The topic to filter repositories by (e.g., `struct-enabled`). - -#### Example - -```sh -export GITHUB_TOKEN=your_personal_access_token -python3 scripts/github-trigger.py my-org struct-enabled -``` - -### How It Works - -1. The script connects to the GitHub API using the provided token. -2. It iterates through all private repositories in the specified organization. -3. For each repository: - - Checks if the repository has the specified topic. - - Verifies the existence of a `.struct.yaml` file in the default branch. - - Confirms the presence of the `run-struct` workflow file. - - Triggers the workflow dispatch event if all conditions are met. - -### Notes - -- Ensure the `GITHUB_TOKEN` environment variable is set before running the script. -- The token must have sufficient permissions to access private repositories and trigger workflows. -- Errors during execution (e.g., missing files or insufficient permissions) will be logged to the console. - -### Advanced Usage - -Add additional parameters to customize the script's behavior: - -- `--dry-run`: Simulate the script actions without executing any API calls. -- `--verbose`: Enable verbose output for debugging purposes. - -Example: - -```sh -python3 scripts/github-trigger.py my-org struct-enabled --dry-run --verbose -``` - -### Troubleshooting - -- **Unauthorized Error**: Make sure your token has the appropriate permissions. -- **Repository Not Found**: Ensure the organization name is correct and the token has access. -- **Missing Files**: Verify that the `.struct.yaml` and workflow files exist in each repository. +STRUCT can seamlessly integrate with GitHub to automate the generation of project structures across repositories. ## Automating STRUCT diff --git a/scripts/github-trigger.py b/scripts/github-trigger.py deleted file mode 100644 index d740680..0000000 --- a/scripts/github-trigger.py +++ /dev/null @@ -1,57 +0,0 @@ -import os -from github import Github -import argparse -import logging - -# Configure logging -logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') - -def get_repositories_with_topic(org_name, topic): - """Fetch all repositories in an organization with a specific topic.""" - token = os.getenv("GITHUB_TOKEN") - if not token: - raise EnvironmentError("GITHUB_TOKEN environment variable is not set.") - - github = Github(token) - org = github.get_organization(org_name) - repos_with_topic = [] - - for repo in org.get_repos(): - if topic in repo.get_topics(): - repos_with_topic.append(repo) - - return repos_with_topic - -def trigger_workflow(repo): - """Trigger the 'run-struct.yaml' workflow for a given repository.""" - workflows = repo.get_workflows() - for workflow in workflows: - if workflow.path.endswith("run-struct.yaml"): - workflow.create_dispatch(ref=repo.default_branch) - logging.info(f"Triggered workflow for repository: {repo.full_name}") - return - - logging.warning(f"No 'run-struct.yaml' workflow found in repository: {repo.full_name}") - -def main(): - parser = argparse.ArgumentParser(description="Trigger 'run-struct.yaml' workflow for repositories with a specific topic.") - parser.add_argument("--org", required=True, help="The GitHub organization name.") - parser.add_argument("--topic", required=True, help="The topic to filter repositories by.") - - args = parser.parse_args() - - org_name = args.org - topic = args.topic - - try: - repos = get_repositories_with_topic(org_name, topic) - logging.info(f"Found {len(repos)} repositories with topic '{topic}'.") - - for repo in repos: - trigger_workflow(repo) - - except Exception as e: - logging.error(f"Error: {e}") - -if __name__ == "__main__": - main() diff --git a/struct_module/contribs/prompts/run-struct-trigger.yaml b/struct_module/contribs/prompts/run-struct-trigger.yaml new file mode 100644 index 0000000..8852c7e --- /dev/null +++ b/struct_module/contribs/prompts/run-struct-trigger.yaml @@ -0,0 +1,18 @@ +files: + - run-struct-trigger.md: + content: | + You are a helpful assistant that can query Github Using MCP + + I will need you to get the list of repositories that have the following topic: "{{@ topic @}}" + The organization should be "{{@ github_organization @}}" + + To all those repositories, you will need to trigger a workflow called "run-struct" + +variables: + - github_organization: + type: string + description: The organization to query for repositories + - topic: + type: string + description: The topic to query for repositories + default: "struct-enabled"