Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/ghfind-py/ghfind/_co_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def co_creator_share(f):
return share*smooth(share/SHARE_FADE)


_CORE_SOURCE = re.compile(r'\.(c|cc|cpp|cs|go|java|js|jsx|mjs|cjs|kt|php|py|rb|rs|scala|swift|ts|tsx|vue|svelte|css|scss)$')
_CORE_SOURCE = re.compile(r'\.(c|cc|cpp|cs|go|java|js|jsx|mjs|cjs|kt|lua|php|py|rb|rs|scala|swift|ts|tsx|vue|svelte|css|scss)$')
_GENERATED_PATH = re.compile(r'(^|/)(vendor|vendored|third[_-]?party|node_modules|dist|build|out|generated|__generated__|gen)/|\.(min\.js|pb\.go|pb\.gw\.go|pb\.ts|g\.dart|freezed\.dart|generated\.\w+)$|_pb2(_grpc)?\.py$|\.d\.ts$')
_BOT_LOGIN = re.compile(r'\[bot\]$|-bot$|^(dependabot|renovate|github-actions|copilot-swe-agent)', re.I)

Expand Down
2 changes: 1 addition & 1 deletion packages/ghfind-py/ghfind/_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ def _is_core_code_path(path: str, ui_library=False) -> bool:
p = path.lower()
if _is_doc_like_path(p) or _is_presentation_only_path(p, ui_library):
return False
return bool((ui_library and re.search(r"\.(css|scss|sass|less|styl)$",p)) or re.search(r"\.(c|cc|cpp|cs|go|java|js|jsx|kt|m|mm|php|py|rb|rs|scala|swift|ts|tsx)$", p, re.I))
return bool((ui_library and re.search(r"\.(css|scss|sass|less|styl)$",p)) or re.search(r"\.(c|cc|cpp|cs|go|java|js|jsx|kt|lua|m|mm|php|py|rb|rs|scala|swift|ts|tsx)$", p, re.I))


def _is_presentation_only_path(path: str, ui_library=False) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion packages/ghfind-py/ghfind/_presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re

UI_LIBRARY = re.compile(r'(^|[-_./])(ui|design|design-system|components?|widgets?|styles?|css|themes?|antd|mui|chakra|shadcn|patternfly|tailwind(css)?)([-_./]|$)', re.I)
CORE_FILE = re.compile(r'\.(c|cc|cpp|cs|go|java|js|jsx|kt|m|mm|php|py|rb|rs|scala|swift|ts|tsx|vue|svelte|css|scss|sass|less|styl)$', re.I)
CORE_FILE = re.compile(r'\.(c|cc|cpp|cs|go|java|js|jsx|kt|lua|m|mm|php|py|rb|rs|scala|swift|ts|tsx|vue|svelte|css|scss|sass|less|styl)$', re.I)
SITE = re.compile(r'(^|[-_./])(site|website|blog|docs?|homepage)([-_./]|$)|site$|\.github\.io$', re.I)

def is_presentation_path(path, repo, doc_site=False):
Expand Down
5 changes: 5 additions & 0 deletions packages/ghfind-py/tests/test_co_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ def test_shared_cap_boundaries(case):
assert low_prestige_bulk_contribution_cap(case['metrics']) == pytest.approx(case['expected'],abs=1e-10)

from ghfind._co_creator import weighted_core_churn, summarize_contributors
from ghfind._extract import impact_code_sample
CONTENT=json.loads((Path(__file__).resolve().parents[3]/'scoring/fixtures/contribution-content-fixtures.json').read_text())
@pytest.mark.parametrize('case',CONTENT['legacy_impact'],ids=lambda c:c['name'])
def test_legacy_core_code_evidence(case):
assert impact_code_sample(case['prs']) == case['expected']

@pytest.mark.parametrize('case',CONTENT['churn'],ids=lambda c:c['name'])
def test_content_weighted_core_churn(case):
core,total,fresh=weighted_core_churn(case['files'],case['repo'])
Expand Down
143 changes: 143 additions & 0 deletions scoring/fixtures/contribution-content-fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,95 @@
"total": 0,
"fresh": 0
}
},
{
"name": "lua-runtime-source",
"repo": "org-x/game-mod",
"files": [
{
"path": "mod/runtime.lua",
"additions": 100,
"deletions": 10
}
],
"expected": {
"core": 110,
"total": 110,
"fresh": 110
}
},
{
"name": "lua-vendored-generated-and-presentation-excluded",
"repo": "org-x/game-mod",
"files": [
{
"path": "vendor/runtime.lua",
"additions": 100,
"deletions": 0
},
{
"path": "third_party/runtime.lua",
"additions": 100,
"deletions": 0
},
{
"path": "generated/runtime.lua",
"additions": 100,
"deletions": 0
},
{
"path": "dist/runtime.lua",
"additions": 100,
"deletions": 0
},
{
"path": "docs/example.lua",
"additions": 100,
"deletions": 0
},
{
"path": "README.lua",
"additions": 100,
"deletions": 0
}
],
"expected": {
"core": 0,
"total": 600,
"fresh": 0
}
},
{
"name": "lua-rewrite-retains-discount-and-file-cap",
"repo": "org-x/game-mod",
"files": [
{
"path": "mod/runtime.lua",
"additions": 1000,
"deletions": 1000
}
],
"expected": {
"core": 150,
"total": 2000,
"fresh": 0
}
},
{
"name": "lua-new-code-retains-file-cap",
"repo": "org-x/game-mod",
"files": [
{
"path": "mod/runtime.lua",
"additions": 2000,
"deletions": 0
}
],
"expected": {
"core": 1500,
"total": 2000,
"fresh": 1500
}
}
],
"contributors": [
Expand Down Expand Up @@ -231,5 +320,59 @@
"leading_commits": 40
}
}
],
"legacy_impact": [
{
"name": "lua-with-readme-is-code",
"prs": [
{
"title": "fix runtime",
"repo": "org-x/game-mod",
"files": [
"mod/runtime.lua",
"README.md"
]
}
],
"expected": {
"pr_sample": 1,
"code_pr_sample": 1
}
},
{
"name": "lua-documentation-examples-stay-doc-like",
"prs": [
{
"title": "fix example",
"repo": "org-x/game-mod",
"files": [
"docs/example.lua",
"README.md"
]
}
],
"expected": {
"pr_sample": 1,
"code_pr_sample": 0
}
},
{
"name": "lua-doc-heavy-sample-stays-doc-like",
"prs": [
{
"title": "update runtime and guides",
"repo": "org-x/game-mod",
"files": [
"mod/runtime.lua",
"README.md",
"docs/usage.md"
]
}
],
"expected": {
"pr_sample": 1,
"code_pr_sample": 0
}
}
]
}
63 changes: 63 additions & 0 deletions scoring/fixtures/presentation-fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -1162,5 +1162,68 @@
"presentation_core_churn_share": 1
},
"discount": 1
},
{
"name": "lua-core-churn-protects-mixed-maintainer",
"prs": [
{
"repo": "org/game-mod",
"repo_stars": 1000,
"title": "update runtime and readme",
"churn": 1000,
"changed_files": 2,
"file_changes": [
{
"path": "mod/runtime.lua",
"additions": 400,
"deletions": 0
},
{
"path": "README.md",
"additions": 600,
"deletions": 0
}
],
"trivial": false
}
],
"own_repos": [],
"expected": {
"presentation_churn_share": 0.6,
"presentation_repo_concentration": 1,
"presentation_pr_sample": 1,
"presentation_core_pr_count": 0,
"presentation_core_churn_share": 0.4
},
"discount": 1
},
{
"name": "lua-documentation-path-stays-presentation",
"prs": [
{
"repo": "org/game-mod",
"repo_stars": 1000,
"title": "update example",
"churn": 100,
"changed_files": 1,
"file_changes": [
{
"path": "docs/example.lua",
"additions": 100,
"deletions": 0
}
],
"trivial": false
}
],
"own_repos": [],
"expected": {
"presentation_churn_share": 1,
"presentation_repo_concentration": 1,
"presentation_pr_sample": 1,
"presentation_core_pr_count": 0,
"presentation_core_churn_share": 0
},
"discount": 0.7666666666666667
}
]
2 changes: 1 addition & 1 deletion scoring/presentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var presentationCore = regexp.MustCompile(`\.(c|cc|cpp|cs|go|java|kt|m|mm|php|py
var presentationServer = regexp.MustCompile(`(^|/)(server|backend|api|database|db|auth)(/|$)`)
var presentationJS = regexp.MustCompile(`\.(jsx?|tsx?)$`)
var presentationDocusaurus = regexp.MustCompile(`(^|/)docusaurus\.config\.[cm]?[jt]s$`)
var presentationCoreFile = regexp.MustCompile(`(?i)\.(c|cc|cpp|cs|go|java|js|jsx|kt|m|mm|php|py|rb|rs|scala|swift|ts|tsx|vue|svelte|css|scss|sass|less|styl)$`)
var presentationCoreFile = regexp.MustCompile(`(?i)\.(c|cc|cpp|cs|go|java|js|jsx|kt|lua|m|mm|php|py|rb|rs|scala|swift|ts|tsx|vue|svelte|css|scss|sass|less|styl)$`)
var presentationStyle = regexp.MustCompile(`\.(css|scss|sass|less|styl)$`)
var presentationPaths = []*regexp.Regexp{
regexp.MustCompile(`(?i)(^|/)(assets?|public|static)/.*(?:\.[a-z0-9_-]{6,}\.m?js|\.min\.js)$`),
Expand Down
46 changes: 46 additions & 0 deletions scoring/presentation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package scoring

import (
"encoding/json"
"math"
"os"
"testing"
)

func TestPresentationSignalsMatchSharedFixtures(t *testing.T) {
data, err := os.ReadFile("fixtures/presentation-fixtures.json")
if err != nil {
t.Fatal(err)
}
var fixtures []struct {
Name string `json:"name"`
PRs []RecentPR `json:"prs"`
OwnRepos []string `json:"own_repos"`
Expected map[string]float64 `json:"expected"`
Discount float64 `json:"discount"`
}
if err := json.Unmarshal(data, &fixtures); err != nil {
t.Fatal(err)
}
for _, f := range fixtures {
t.Run(f.Name, func(t *testing.T) {
var metrics RawMetrics
applyPresentationSignals(&metrics, f.PRs, "fixture-account-045", f.OwnRepos)
actual := map[string]float64{
"presentation_churn_share": *metrics.PresentationChurnShare,
"presentation_core_churn_share": *metrics.PresentationCoreChurnShare,
"presentation_repo_concentration": *metrics.PresentationRepoConcentration,
"presentation_pr_sample": *metrics.PresentationPRSample,
"presentation_core_pr_count": *metrics.PresentationCorePRCount,
}
for key, want := range f.Expected {
if got, ok := actual[key]; !ok || math.Abs(got-want) > 1e-12 {
t.Errorf("%s: got %v want %v", key, got, want)
}
}
if got := presentationDiscount(metrics); math.Abs(got-f.Discount) > 1e-12 {
t.Errorf("discount: got %v want %v", got, f.Discount)
}
})
}
}
2 changes: 1 addition & 1 deletion scoring/src/co-creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export function budgetCoCreatorShares<T extends { attribution_share?: number; co
return repos.map(repo => ({...repo, attribution_share: projectShare(repo)*(repo.co_creator_facts?.first_author ? 1 : multiplier)}));
}

const CORE_SOURCE = /\.(c|cc|cpp|cs|go|java|js|jsx|mjs|cjs|kt|php|py|rb|rs|scala|swift|ts|tsx|vue|svelte|css|scss)$/;
const CORE_SOURCE = /\.(c|cc|cpp|cs|go|java|js|jsx|mjs|cjs|kt|lua|php|py|rb|rs|scala|swift|ts|tsx|vue|svelte|css|scss)$/;
/** Vendored, generated and build-output paths never count as authored core code. */
const GENERATED_PATH = /(^|\/)(vendor|vendored|third[_-]?party|node_modules|dist|build|out|generated|__generated__|gen)\/|\.(min\.js|pb\.go|pb\.gw\.go|pb\.ts|g\.dart|freezed\.dart|generated\.\w+)$|_pb2(_grpc)?\.py$|\.d\.ts$/;
/** Per-file churn cap: one huge file cannot carry a contribution on its own. */
Expand Down
2 changes: 1 addition & 1 deletion scoring/src/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ function isCoreCodePath(path: string, uiLibrary = false): boolean {
const p = path.toLowerCase();
if (isDocLikePath(p) || isPresentationOnlyPath(p, uiLibrary)) return false;
if (uiLibrary && STYLE_FILE.test(p)) return true;
return /\.(c|cc|cpp|cs|go|java|js|jsx|kt|m|mm|php|py|rb|rs|scala|swift|ts|tsx)$/i.test(
return /\.(c|cc|cpp|cs|go|java|js|jsx|kt|lua|m|mm|php|py|rb|rs|scala|swift|ts|tsx)$/i.test(
p,
);
}
Expand Down
2 changes: 1 addition & 1 deletion scoring/src/presentation-concentration.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { RawMetrics, RecentPr } from "./types";

const UI_LIBRARY = /(^|[-_./])(ui|design|design-system|components?|widgets?|styles?|css|themes?|antd|mui|chakra|shadcn|patternfly|tailwind(css)?)([-_./]|$)/i;
const CORE_FILE = /\.(c|cc|cpp|cs|go|java|js|jsx|kt|m|mm|php|py|rb|rs|scala|swift|ts|tsx|vue|svelte|css|scss|sass|less|styl)$/i;
const CORE_FILE = /\.(c|cc|cpp|cs|go|java|js|jsx|kt|lua|m|mm|php|py|rb|rs|scala|swift|ts|tsx|vue|svelte|css|scss|sass|less|styl)$/i;
const STYLE = /\.(css|scss|sass|less|styl)$/i;
const SITE = /(^|[-_./])(site|website|blog|docs?|homepage)([-_./]|$)|site$|\.github\.io$/i;

Expand Down
5 changes: 5 additions & 0 deletions scoring/test/co-creator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ it('keeps the cap bounded and nondecreasing with prestige across core levels', (

import contentFx from '../fixtures/contribution-content-fixtures.json';
import {weightedCoreChurn,summarizeContributors} from '../src/co-creator';
import {impactCodeSample} from '../src/extract';
import type {RecentPr} from '../src/types';
it.each(contentFx.legacy_impact)('legacy core-code evidence: $name',c=>{
expect(impactCodeSample(c.prs as RecentPr[])).toEqual(c.expected);
});
it.each(contentFx.churn)('content-weighted core churn: $name',c=>{
expect(weightedCoreChurn(c.files,c.repo)).toEqual(c.expected);
});
Expand Down
Loading