GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — git: alternative github context and additional methods by crazy-max · Pull Request #55 · docker/actions-toolkit

Conversation

@crazy-max

@crazy-max crazy-max commented Feb 25, 2023

Copy link
Copy Markdown
Member

follow-up docker/metadata-action#248

Adds alternative context to the GitHub one for Git.

@neilime PTAL. I keep you posted when we cut a new release of the actions-toolkit so you can rebase your PR on the metadata-action repo. You could then have smth like:

---
 src/context.ts | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/context.ts b/src/context.ts
index 3738b23..dd819c9 100644
--- a/src/context.ts
+++ b/src/context.ts
@@ -1,7 +1,11 @@
 import * as core from '@actions/core';
+import {Context} from '@actions/github/lib/context';
+import {Git} from '@docker/actions-toolkit/lib/git';
+import {GitHub} from '@docker/actions-toolkit/lib/github';
 import {Util} from '@docker/actions-toolkit/lib/util';
 
 export interface Inputs {
+  context: Context;
   images: string[];
   tags: string[];
   flavor: string[];
@@ -12,8 +16,9 @@ export interface Inputs {
   githubToken: string;
 }
 
-export function getInputs(): Inputs {
+export async function getInputs(): Promise<Inputs> {
   return {
+    context: await getContextInput('context'),
     images: Util.getInputList('images', {ignoreComma: true}),
     tags: Util.getInputList('tags', {ignoreComma: true}),
     flavor: Util.getInputList('flavor', {ignoreComma: true}),
@@ -24,3 +29,20 @@ export function getInputs(): Inputs {
     githubToken: core.getInput('github-token')
   };
 }
+
+export enum ContextSource {
+  workflow = 'workflow',
+  git = 'git'
+}
+
+async function getContextInput(name: string): Promise<Context> {
+  const input = core.getInput(name);
+  switch (input) {
+    case ContextSource.workflow:
+      return GitHub.context;
+    case ContextSource.git:
+      return await Git.context();
+    default:
+      throw new Error(`Invalid context: ${input}`);
+  }
+}

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

neilime reacted with eyes emoji
All reactions
  • 👀 1 reaction
@crazy-max
crazy-max force-pushed the git-context branch 2 times, most recently from 442a46c to b8325fe Compare February 25, 2023 06:08
@crazy-max
crazy-max marked this pull request as ready for review February 25, 2023 11:13
@crazy-max
git: alternative github context and additional methods
8a69d6c
Signed-off-by: CrazyMax <[email protected]>
@crazy-max
crazy-max force-pushed the git-context branch from b8325fe to 8a69d6c Compare February 25, 2023 11:37
@crazy-max
crazy-max merged commit 53ca96f into docker:main Mar 2, 2023
@crazy-max
crazy-max deleted the git-context branch March 2, 2023 14:50
@neilime

neilime commented Mar 3, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

@crazy-max I've done the job on docker/metadata-action#248, waiting for you review

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@crazy-max @neilime
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.