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

results: Use git rev-parse for getting commit hash #100

Merged
merged 1 commit into from
Jan 21, 2025
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
24 changes: 20 additions & 4 deletions docs/results.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ kci-dev results build --giturl 'https://git.kernel.org/pub/scm/linux/kernel/git/

If used without arguments, `kci-dev results` subcommands will get KernelCI status
of local checked out git repository for commands that require a giturl and branch.
In the following example, kci-dev is used on a local linux repository folder
In the following example, kci-dev is used on a local linux repository folder.
This command work with every linux repository supported by KernelCI

```sh
Expand All @@ -105,7 +105,6 @@ git folder: None
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
branch: master
commit: fbfd64d25c7af3b8695201ebc85efe90be28c5a3

pass/fail/inconclusive
builds: 46/0/0
boots: 580/48/8
Expand All @@ -117,14 +116,31 @@ tests: 7858/6903/654
Get results automatically from a folder with a local linux repository.

```sh
kci-dev git:(master)$ kci-dev results --git-folder ../linux
kci-dev git:(master)$ kci-dev results summary --git-folder ../linux
git folder: ../linux
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
branch: master
commit: fbfd64d25c7af3b8695201ebc85efe90be28c5a3

pass/fail/inconclusive
builds: 46/0/0
boots: 580/48/8
tests: 7858/6903/654
```

## --branch

In the case of the script not been able to get the current branch information,
like in the case of a detached HEAD, it is possible to specify a branch.
Like in the following case:

```sh
linux-cip git:(6077b17f20b1) kci-dev results summary --branch linux-5.10.y-cip
git folder: None
tree: https://git.kernel.org/pub/scm/linux/kernel/git/cip/linux-cip.git
branch: linux-5.10.y-cip
commit: 6077b17f20b1bcfeccaa23bc05573b938c47679d
pass/fail/inconclusive
builds: 21/0/0
boots: 440/36/18
tests: 1190/184/100
```
13 changes: 8 additions & 5 deletions kcidev/subcommands/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def is_inside_work_tree(git_folder):
return False


def get_folder_repository(git_folder):
def get_folder_repository(git_folder, branch):
kci_msg("git folder: " + str(git_folder))
if git_folder:
current_folder = git_folder
Expand Down Expand Up @@ -109,12 +109,15 @@ def get_folder_repository(git_folder):
)
branch_name, branch_error = process.communicate()
branch_name = branch_name.strip()
if branch:
branch_name = branch

# Get last commit hash
last_commit_hash_path = os.path.join(
dot_git_folder, "refs", "heads", branch_name
process = subprocess.Popen(
["git", "rev-parse", "HEAD"], stdout=subprocess.PIPE, text=True
)
last_commit_hash = open(last_commit_hash_path, "r").read()
last_commit_hash, last_commit_hash_error = process.communicate()
last_commit_hash = last_commit_hash.strip()

os.chdir(previous_folder)
kci_msg("tree: " + git_url)
Expand Down Expand Up @@ -240,7 +243,7 @@ def cmd_builds(data, commit, download_logs, status):

def set_giturl_branch_commit(origin, giturl, branch, commit, latest, git_folder):
if not giturl or not branch or not ((commit != None) ^ latest):
giturl, branch, commit = get_folder_repository(git_folder)
giturl, branch, commit = get_folder_repository(git_folder, branch)
if latest:
commit = get_latest_commit(origin, giturl, branch)
return giturl, branch, commit
Expand Down
Loading