Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
update 13
Browse files Browse the repository at this point in the history
  • Loading branch information
nitro-neal committed Aug 22, 2024
1 parent ee63fbc commit 086bfe3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 128 deletions.
37 changes: 31 additions & 6 deletions reports/report-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ <h2 id="{{ $category }}_table-caption">{{ $category }}</h2>
<a target="_blank" href="https://github.com/{{ .SDK.Repo }}"
>{{ .SDK.Name }}</a
>

<p>{{ .SDK.SubmoduleCommit }} </p>
<p>{{ .SDK.SubmoduleCommitBehind }} </p>
</th>
{{ end }}
</tr>
Expand Down Expand Up @@ -85,9 +82,6 @@ <h2 id="{{ $category }}_table-caption">{{ $category }}</h2>
<a target="_blank" href="https://github.com/{{ .SDK.Repo }}"
>{{ .SDK.Name }}</a
>

<p>{{ .SDK.SubmoduleCommit }} </p>
<p>{{ .SDK.SubmoduleCommitBehind }} </p>
</th>
{{ end }}
</tr>
Expand Down Expand Up @@ -115,6 +109,37 @@ <h2 id="{{ $category }}_table-caption">{{ $category }}</h2>
{{ end }}
</table>
{{ end }}

<hr/>
<h1>SDK Repository Submodule Information</h1>
<table>
<thead>
<tr>
<th>SDK</th>
<th>Repository</th>
<th>Submodule Commit</th>
<th>Commits Behind</th>
</tr>
</thead>
<tbody>
{{ range $.Web5Reports }}
<tr>
<td>{{ .SDK.Name }}</td>
<td><a href="https://github.com/{{ .SDK.Repo }}" target="_blank">{{ .SDK.Repo }}</a></td>
<td>{{ .SDK.SubmoduleCommit }}</td>
<td>{{ .SDK.SubmoduleCommitBehind }}</td>
</tr>
{{ end }}
{{ range $.TbdexReports }}
<tr>
<td>{{ .SDK.Name }}</td>
<td><a href="https://github.com/{{ .SDK.Repo }}" target="_blank">{{ .SDK.Repo }}</a></td>
<td>{{ .SDK.SubmoduleCommit }}</td>
<td>{{ .SDK.SubmoduleCommitBehind }}</td>
</tr>
{{ end }}
</tbody>
</table>
<!-- Display creation time at the bottom of the page -->
<div style="text-align: center; margin-top: 20px;">
<strong>Report generated on: {{ .CreationTime }}</strong>
Expand Down
125 changes: 3 additions & 122 deletions reports/sdks.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,9 @@ func CheckSubmoduleStatus2(ctx context.Context) error {
tbdexOpt.Page = resp.NextPage
}

for _, sdk := range SDKs {
// Iterate using index to modify the original SDKMeta in the slice
for i := range SDKs {
sdk := &SDKs[i] // Get the pointer to the current SDKMeta in the slice

// default values
sdk.SubmoduleCommit = "-"
Expand Down Expand Up @@ -416,127 +418,6 @@ func CheckSubmoduleStatus2(ctx context.Context) error {
return nil
}

func CheckSubmoduleStatus(ctx context.Context) error {
for _, sdk := range SDKs {
owner, repo, _ := strings.Cut(sdk.Repo, "/")

// Determine submodule name based on SDK type
submoduleName := "web5-spec"
if sdk.Type == "tbdex" {
submoduleName = "tbdex"
}

// Get the current submodule commit
submoduleRef, _, err := gh.Git.GetRef(ctx, owner, repo, "heads/main")
if err != nil {
return fmt.Errorf("error getting ref for %s: %v", sdk.Repo, err)
}

tree, _, err := gh.Git.GetTree(ctx, owner, repo, *submoduleRef.Object.SHA, true)
if err != nil {
return fmt.Errorf("error getting tree for %s: %v", sdk.Repo, err)
}

var submoduleCommit string
for _, entry := range tree.Entries {
if *entry.Path == submoduleName {
submoduleCommit = *entry.SHA
break
}
}

if submoduleCommit == "" {
fmt.Printf("submodule %s not found in %s\n", submoduleName, sdk.Repo)
continue
}

// Get the latest commit of the submodule repo
submoduleOwner := "TBD54566975"
submoduleRepo := submoduleName
latestCommit, _, err := gh.Repositories.GetCommit(ctx, submoduleOwner, submoduleRepo, "main", nil)
if err != nil {
return fmt.Errorf("error getting latest commit for %s: %v", submoduleRepo, err)
}

// Manual count of commits behind or ahead
commits, _, err := gh.Repositories.ListCommits(ctx, submoduleOwner, submoduleRepo, &github.CommitsListOptions{
SHA: "main",
})
if err != nil {
return fmt.Errorf("error listing commits for %s: %v", submoduleRepo, err)
}

var commitsBehind int
var commitsAhead int
var found bool

for i, commit := range commits {
if *commit.SHA == submoduleCommit {
commitsBehind = i
found = true
break
}
}

if !found {
// If not found, the submodule might be ahead
//commits, _, err = gh.Repositories.ListCommits(ctx, submoduleOwner, submoduleRepo, &github.CommitsListOptions{
// SHA: submoduleCommit,
//})

commits, _, err := gh.Repositories.ListCommits(ctx, submoduleOwner, submoduleRepo, &github.CommitsListOptions{
SHA: "main",
ListOptions: github.ListOptions{
PerPage: 100, // Increase this number to retrieve more commits per page
},
})

if err != nil {
return fmt.Errorf("error listing commits for %s: %v", submoduleRepo, err)
}

for i, commit := range commits {
if *commit.SHA == *latestCommit.SHA {
commitsAhead = i
found = true
break
}
}
}

if !found {
slog.Warn("Unable to determine relative position of submodule",
"repo", sdk.Repo,
"submodule", submoduleName,
"submodule_commit", submoduleCommit[:7],
"main_commit", (*latestCommit.SHA)[:7])
} else if commitsBehind > 0 {
slog.Info("Submodule status",
"repo", sdk.Repo,
"submodule", submoduleName,
"submodule_commit", submoduleCommit[:7],
"main_commit", (*latestCommit.SHA)[:7],
"commits_behind", commitsBehind)
} else if commitsAhead > 0 {
slog.Info("Submodule status",
"repo", sdk.Repo,
"submodule", submoduleName,
"submodule_commit", submoduleCommit[:7],
"main_commit", (*latestCommit.SHA)[:7],
"commits_ahead", commitsAhead)
} else {
slog.Info("Submodule is up to date",
"repo", sdk.Repo,
"submodule", submoduleName,
"commit", submoduleCommit[:7])
}

slog.Info("--------------------")
}

return nil
}

// Used for testing purposes
func downloadLocal(ctx context.Context, sdk SDKMeta) ([]byte, error) {
//data, err := os.ReadFile("../tbdex-junit-results.zip")
Expand Down

0 comments on commit 086bfe3

Please sign in to comment.