{
  "nbformat": 4,
  "nbformat_minor": 5,
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "version": "3.13.0"
    },
    "blog_metadata": {
      "topic": "What GitHub's Open Source Collaboration Graph Says About Enterprise Engineering Strategy",
      "slug": "what-github-s-open-source-collaboration-graph-says-about-ent",
      "generated_by": "LinkedIn Post Generator + Azure OpenAI",
      "generated_at": "2026-07-10T13:11:01.657Z"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# What GitHub's Open Source Collaboration Graph Says About Enterprise Engineering Strategy\n",
        "\n",
        "This notebook turns the blog post into a hands-on validation workflow using Python. The focus is not popularity metrics like stars or forks, but signals of engineering compounding: shared interfaces, reusable workflows, contribution overlap, governance defaults, and standardized APIs.\n",
        "\n",
        "You will build small collaboration and reuse analyses, simulate governance automation against GitHub-style REST endpoints, and inspect how identity APIs like Microsoft Graph support scalable policy workflows."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "%pip install -q requests pandas networkx matplotlib"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "import os\n",
        "import json\n",
        "from collections import defaultdict, Counter\n",
        "\n",
        "import requests\n",
        "import pandas as pd\n",
        "import networkx as nx\n",
        "import matplotlib.pyplot as plt"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Operating model signal: from collaboration graph to enterprise leverage\n",
        "\n",
        "The blog argues that a collaboration graph becomes strategically useful only when it resolves into shared standards, reusable tooling, and governance guardrails that accelerate integrations. The code below represents that logic as a directed graph and computes simple structural properties you can inspect."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "import networkx as nx\n",
        "import matplotlib.pyplot as plt\n",
        "\n",
        "G = nx.DiGraph()\n",
        "edges = [\n",
        "    (\"Open Source Collaboration Graph\", \"Shared standards\"),\n",
        "    (\"Open Source Collaboration Graph\", \"Reusable tooling\"),\n",
        "    (\"Open Source Collaboration Graph\", \"Cross-team visibility\"),\n",
        "    (\"Shared standards\", \"Stable enterprise APIs\"),\n",
        "    (\"Reusable tooling\", \"Automation at scale\"),\n",
        "    (\"Cross-team visibility\", \"Governance and guardrails\"),\n",
        "    (\"Stable enterprise APIs\", \"Faster integrations\"),\n",
        "    (\"Automation at scale\", \"Faster integrations\"),\n",
        "    (\"Governance and guardrails\", \"Faster integrations\"),\n",
        "]\n",
        "G.add_edges_from(edges)\n",
        "\n",
        "print(\"Nodes:\", list(G.nodes()))\n",
        "print(\"Edges:\", list(G.edges()))\n",
        "print(\"In-degree of 'Faster integrations':\", G.in_degree(\"Faster integrations\"))\n",
        "print(\"Ancestors of 'Faster integrations':\", sorted(nx.ancestors(G, \"Faster integrations\")))\n",
        "\n",
        "plt.figure(figsize=(10, 6))\n",
        "pos = nx.spring_layout(G, seed=42)\n",
        "nx.draw(G, pos, with_labels=True, node_size=2800, font_size=9, arrows=True)\n",
        "plt.title(\"Operating Model Graph\")\n",
        "plt.show()"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Tiny collaboration graph from contribution events\n",
        "\n",
        "This example recreates the blog's point that overlap matters more than raw activity. We group contribution events by repository and inspect which engineers appear across strategic repos."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "from collections import defaultdict\n",
        "\n",
        "events = [\n",
        "    (\"payments-api\", \"alice\"), (\"payments-api\", \"bob\"),\n",
        "    (\"identity-sdk\", \"alice\"), (\"identity-sdk\", \"carol\"),\n",
        "    (\"platform-cli\", \"bob\"), (\"platform-cli\", \"carol\"),\n",
        "]\n",
        "\n",
        "graph = defaultdict(set)\n",
        "for repo, engineer in events:\n",
        "    graph[repo].add(engineer)\n",
        "\n",
        "for repo, engineers in graph.items():\n",
        "    print(f\"{repo}: {sorted(engineers)}\")\n",
        "\n",
        "shared = graph[\"payments-api\"] & graph[\"platform-cli\"]\n",
        "print(\"Cross-project overlap:\", sorted(shared))"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Score repositories by cross-team reuse\n",
        "\n",
        "A repository reused by multiple teams often signals platform value better than a noisy application repository. This code ranks repositories by the number of consuming teams as a simple proxy for enterprise leverage."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "repos = {\n",
        "    \"identity-sdk\": {\"appdev\", \"security\", \"platform\"},\n",
        "    \"payments-api\": {\"appdev\", \"finance\"},\n",
        "    \"platform-cli\": {\"platform\", \"security\", \"data\"},\n",
        "    \"design-system\": {\"web\", \"mobile\", \"marketing\"},\n",
        "}\n",
        "\n",
        "scores = {name: len(consumers) for name, consumers in repos.items()}\n",
        "ranked = sorted(scores.items(), key=lambda item: item[1], reverse=True)\n",
        "\n",
        "for name, score in ranked:\n",
        "    print(f\"{name}: reused by {score} teams\")\n",
        "\n",
        "pd.DataFrame(ranked, columns=[\"repository\", \"reuse_score\"])"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Required environment variables for Microsoft Graph example\n",
        "\n",
        "Set the following variable before running the next cell:\n",
        "\n",
        "- `MS_GRAPH_TOKEN`: Bearer token with permission to call Microsoft Graph.\n",
        "\n",
        "If the token is missing or still set to the placeholder value, the code will skip the live API call safely."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Query Microsoft Graph through a standardized API\n",
        "\n",
        "The blog's argument is that standardized APIs create reusable automation. This example calls Microsoft Graph to retrieve a few users and demonstrates how one governed interface can support ownership mapping, onboarding, and policy workflows."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "import os\n",
        "import requests\n",
        "\n",
        "token = os.getenv(\"MS_GRAPH_TOKEN\", \"replace-with-bearer-token\")\n",
        "url = \"https://graph.microsoft.com/v1.0/users?$top=3&$select=id,displayName,mail\"\n",
        "\n",
        "if token == \"replace-with-bearer-token\":\n",
        "    print(\"Skipping live Microsoft Graph call. Set MS_GRAPH_TOKEN to run this example.\")\n",
        "else:\n",
        "    response = requests.get(url, headers={\"Authorization\": f\"Bearer {token}\"}, timeout=20)\n",
        "    response.raise_for_status()\n",
        "\n",
        "    for user in response.json().get(\"value\", []):\n",
        "        print(f\"{user.get('displayName')} <{user.get('mail')}>\")"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Policy automation sequence as executable workflow data\n",
        "\n",
        "The original post uses a sequence diagram to show how repo creation can trigger policy automation backed by identity data. Here we model the same sequence as structured Python data so it can be inspected, logged, or extended into tests."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "steps = [\n",
        "    (\"Engineer\", \"Git Platform\", \"Create repo or app registration\"),\n",
        "    (\"Git Platform\", \"Guardrail Automation\", \"Trigger policy workflow\"),\n",
        "    (\"Guardrail Automation\", \"Identity/Graph API\", \"Resolve owner/team metadata\"),\n",
        "    (\"Identity/Graph API\", \"Guardrail Automation\", \"Return standardized identity data\"),\n",
        "    (\"Guardrail Automation\", \"Git Platform\", \"Apply labels, branch rules, templates\"),\n",
        "    (\"Git Platform\", \"Engineer\", \"Compliant project ready to use\"),\n",
        "]\n",
        "\n",
        "for i, (src, dst, action) in enumerate(steps, start=1):\n",
        "    print(f\"{i}. {src} -> {dst}: {action}\")\n",
        "\n",
        "workflow_df = pd.DataFrame(steps, columns=[\"from\", \"to\", \"action\"])\n",
        "workflow_df"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Simulate baseline GitHub repository governance settings in Python\n",
        "\n",
        "The blog includes PowerShell examples for GitHub REST API governance. Since this notebook uses Python, the next cell builds the same request payload and prints the endpoint, headers, and body you would send. It avoids making a live change unless you explicitly enable it."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "import os\n",
        "import json\n",
        "\n",
        "owner = os.getenv(\"GITHUB_OWNER\", \"contoso\")\n",
        "repo = os.getenv(\"GITHUB_REPO\", \"platform-cli\")\n",
        "token = os.getenv(\"GITHUB_TOKEN\", \"\")\n",
        "\n",
        "headers = {\n",
        "    \"Authorization\": f\"Bearer {token}\" if token else \"Bearer <missing>\",\n",
        "    \"Accept\": \"application/vnd.github+json\",\n",
        "}\n",
        "\n",
        "body = {\n",
        "    \"has_issues\": True,\n",
        "    \"has_projects\": False,\n",
        "    \"delete_branch_on_merge\": True,\n",
        "    \"allow_squash_merge\": True,\n",
        "    \"allow_merge_commit\": False,\n",
        "}\n",
        "\n",
        "url = f\"https://api.github.com/repos/{owner}/{repo}\"\n",
        "\n",
        "print(\"PATCH\", url)\n",
        "print(\"Headers:\")\n",
        "print(json.dumps(headers, indent=2))\n",
        "print(\"Body:\")\n",
        "print(json.dumps(body, indent=2))"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Simulate repeatable branch protection guardrails in Python\n",
        "\n",
        "This cell mirrors the branch protection PowerShell example using a Python payload. The goal is to validate the shape of a reusable governance baseline that can be applied consistently across repositories."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "import os\n",
        "import json\n",
        "\n",
        "owner = os.getenv(\"GITHUB_OWNER\", \"contoso\")\n",
        "repo = os.getenv(\"GITHUB_REPO\", \"platform-cli\")\n",
        "branch = os.getenv(\"GITHUB_BRANCH\", \"main\")\n",
        "token = os.getenv(\"GITHUB_TOKEN\", \"\")\n",
        "\n",
        "headers = {\n",
        "    \"Authorization\": f\"Bearer {token}\" if token else \"Bearer <missing>\",\n",
        "    \"Accept\": \"application/vnd.github+json\",\n",
        "}\n",
        "\n",
        "protection = {\n",
        "    \"required_status_checks\": {\n",
        "        \"strict\": True,\n",
        "        \"contexts\": [\"build\", \"security-scan\"],\n",
        "    },\n",
        "    \"enforce_admins\": True,\n",
        "    \"required_pull_request_reviews\": {\n",
        "        \"required_approving_review_count\": 2,\n",
        "    },\n",
        "    \"restrictions\": None,\n",
        "}\n",
        "\n",
        "url = f\"https://api.github.com/repos/{owner}/{repo}/branches/{branch}/protection\"\n",
        "\n",
        "print(\"PUT\", url)\n",
        "print(\"Headers:\")\n",
        "print(json.dumps(headers, indent=2))\n",
        "print(\"Body:\")\n",
        "print(json.dumps(protection, indent=2))"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Detect central maintainers across strategic repositories\n",
        "\n",
        "This example identifies engineers whose participation links multiple repositories. These contributors often indicate hidden coordination paths, platform stewardship, or potential bottlenecks in the collaboration graph."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "from collections import Counter\n",
        "\n",
        "repo_contributors = {\n",
        "    \"identity-sdk\": {\"alice\", \"carol\", \"dina\"},\n",
        "    \"platform-cli\": {\"bob\", \"carol\", \"eric\"},\n",
        "    \"payments-api\": {\"alice\", \"frank\"},\n",
        "    \"design-system\": {\"gina\", \"carol\"},\n",
        "}\n",
        "\n",
        "counter = Counter()\n",
        "for contributors in repo_contributors.values():\n",
        "    counter.update(contributors)\n",
        "\n",
        "for engineer, count in counter.most_common():\n",
        "    if count > 1:\n",
        "        print(f\"{engineer} connects {count} repositories\")"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Next Steps\n",
        "\n",
        "This notebook validated the blog's core thesis with executable examples: strategic value comes from contribution overlap, reuse across teams, standardized APIs, and repeatable governance defaults. In enterprise settings, the most important repositories are often the ones that reduce coordination cost and make safe contribution easy.\n",
        "\n",
        "Suggested next steps:\n",
        "- Replace the toy event data with exports from your own GitHub or Azure DevOps environment.\n",
        "- Add metrics for onboarding time, exception rates, and percentage of repos on standard templates.\n",
        "- Turn the governance payloads into live automation only after testing in a sandbox repository.\n",
        "- Enrich collaboration analysis with CODEOWNERS, dependency manifests, and CI policy data.\n",
        "- Rate your organization from 1 to 5 on this question: how easy is it for an engineer from one team to make a safe, governed contribution to another team's strategic repo in under a day?"
      ]
    }
  ]
}