Add Latest Tag sensor to GitHub integration (#66932)

This commit is contained in:
Joakim Sørensen 2022-02-20 13:00:01 +01:00 committed by GitHub
parent 3cbbf90f23
commit 2d52aca9eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 0 deletions

View file

@ -68,6 +68,18 @@ query ($owner: String!, $repository: String!) {
url
tag: tagName
}
refs(
first: 1
refPrefix: "refs/tags/"
orderBy: {field: TAG_COMMIT_DATE, direction: DESC}
) {
tags: nodes {
name
target {
url: commitUrl
}
}
}
}
}
"""

View file

@ -126,6 +126,15 @@ SENSOR_DESCRIPTIONS: tuple[GitHubSensorEntityDescription, ...] = (
"number": data["pull_request"]["pull_requests"][0]["number"],
},
),
GitHubSensorEntityDescription(
key="latest_tag",
name="Latest Tag",
avabl_fn=lambda data: data["refs"]["tags"],
value_fn=lambda data: data["refs"]["tags"][0]["name"][:255],
attr_fn=lambda data: {
"url": data["refs"]["tags"][0]["target"]["url"],
},
),
)

View file

@ -43,6 +43,16 @@
"name": "v1.0.0",
"url": "https://github.com/octocat/Hello-World/releases/v1.0.0",
"tag": "v1.0.0"
},
"refs": {
"tags": [
{
"name": "v1.0.0",
"target": {
"url": "https://github.com/octocat/Hello-World/commit/6dcb09b5b57875f334f61aebed695e2e4193db5e"
}
}
]
}
}
}