Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ implement ListIssues and GetCreatedAt for Azure DevOps #4419

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JamieMagee
Copy link
Contributor

What kind of change does this PR introduce?

(Is it a bug fix, feature, docs update, something else?)

What is the current behavior?

ListIssues and GetCreatedAt throw an unsupported error

What is the new behavior (if this is a feature change)?**

ListIssues and GetCreatedAt have implementations

  • Tests for the changes have been added (for bug fixes/features)

Which issue(s) this PR fixes

Next step of #4177

Special notes for your reviewer

Azure DevOps doesn't have an official API to retrieve user permissions for a project or a repository. As a stopgap solution, I've defaulted all issue and comment authors to RepoAssociationMember. This is probably a good minimum bar.

The audit log is the best way to retrieve the repository creation date, but this may not be enabled. So I am using the first repository commit as a fallback value.

Does this PR introduce a user-facing change?

For user-facing changes, please add a concise, human-readable release note to
the release-note

(In particular, describe what changes users might need to make in their
application as a result of this pull request.)

implement `ListIssues` and `GetCreatedAt` for Azure DevOps

@JamieMagee
Copy link
Contributor Author

With these changes the Maintained check now completes

Details
$ env SCORECARD_EXPERIMENTAL=1 go run . --repo dev.azure.com/jamiemagee/jamiemagee/_git/jamiemagee --checks Maintained
Starting [Maintained]
Finished [Maintained]

RESULTS
-------
Aggregate score: 5.0 / 10

Check scores:
|--------|------------|--------------------------------|-----------------------------------------------------------------------|
| SCORE  |    NAME    |             REASON             |                       DOCUMENTATION/REMEDIATION                       |
|--------|------------|--------------------------------|-----------------------------------------------------------------------|
| 5 / 10 | Maintained | 5 commit(s) and 1 issue        | https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained |
|        |            | activity found in the last 90  |                                                                       |
|        |            | days -- score normalized to 5  |                                                                       |
|--------|------------|--------------------------------|-----------------------------------------------------------------------|

Comment on lines +114 to +116
// If there are fewer commits than requested, the first commit is the createdAt date
if len(*commits) < handler.commitDepth {
handler.firstCommitCreatedAt = (*commits)[len(*commits)-1].Committer.Date.Time
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can azure have a repository with no commits? These edge cases have been issues for Scorecard on other forges and would cause a panic

Comment on lines +60 to +75
// Check if Git.CreateRepo event exists for the repository
for i := range *auditLog.DecoratedAuditLogEntries {
entry := &(*auditLog.DecoratedAuditLogEntries)[i]
if *entry.ActionId == "Git.CreateRepo" &&
*entry.ProjectName == a.repourl.project &&
(*entry.Data)["RepoName"] == a.repourl.name {
a.createdAt = entry.Timestamp.Time
break
}
}

if *auditLog.HasMore {
continuationToken = *auditLog.ContinuationToken
} else {
break
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these breaks could be returns I think. At least the first one, otherwise it will only break out of the inner loop and keep searching the audit log (if there's more)

Comment on lines +74 to +79
// Fetch URI, CreatedAt, Author, and Issue comments
wiql := `
SELECT [System.Id]
FROM WorkItems
WHERE [System.TeamProject] = @project
ORDER BY [System.Id] DESC
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to grab the things we need from this query? or are those details only accessible via GetWorkItems?

Comment on lines +129 to +132
issue := clients.Issue{
URI: wi.Url,
CreatedAt: &parsedTime,
Author: &clients.User{Login: createdBy["uniqueName"].(string)},
Copy link
Member

@spencerschrock spencerschrock Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you check all your other type assertions, did you mean to here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants