-
Notifications
You must be signed in to change notification settings - Fork 10
fix: Enable addition of Private Repos in Spacecat via Slack and add s… #1373
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
Open
vdua
wants to merge
3
commits into
main
Choose a base branch
from
SKYOPS-120433
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+249
−15
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,7 +38,7 @@ function AddRepoCommand(context) { | |
| name: 'Add GitHub Repo', | ||
| description: 'Adds a Github repository to previously added site.', | ||
| phrases: PHRASES, | ||
| usageText: `${PHRASES.join(' or ')} {site} {githubRepoURL}`, | ||
| usageText: `${PHRASES.join(' or ')} {site} {githubRepoURL} [branch]`, | ||
| }); | ||
|
|
||
| const { dataAccess, log } = context; | ||
|
|
@@ -68,6 +68,21 @@ function AddRepoCommand(context) { | |
| } | ||
| } | ||
|
|
||
| async function isOnboardedWithAemy(owner, repo, branch) { | ||
| const AEMY_ENDPOINT = `https://ec-xp-fapp-coordinator.azurewebsites.net/api/fn-ghapp/functions/get_installation_token/${owner}/${repo}/${branch}`; | ||
| try { | ||
| const response = await fetch(AEMY_ENDPOINT, { headers: { 'x-api-key': process.env.AEMY_API_KEY } }); | ||
| if (response.ok) { | ||
| const data = await response.json(); | ||
| return data.token !== null; | ||
| } else { | ||
| throw new Error('Failed to check if repository is onboarded with Aemy'); | ||
| } | ||
| } catch (error) { | ||
| throw new Error(`Failed to check if repository is onboarded with Aemy: ${error.message}`); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Execute function for AddRepoCommand. This function validates the input, fetches the repository | ||
| * information from the GitHub API, and saves it as a site in the database. | ||
|
|
@@ -81,7 +96,7 @@ function AddRepoCommand(context) { | |
| const { say } = slackContext; | ||
|
|
||
| try { | ||
| const [baseURLInput, repoUrlInput] = args; | ||
| const [baseURLInput, repoUrlInput, branchInput] = args; | ||
|
|
||
| const baseURL = extractURLFromSlackInput(baseURLInput); | ||
| let repoUrl = extractURLFromSlackInput(repoUrlInput, false, false); | ||
|
|
@@ -106,22 +121,38 @@ function AddRepoCommand(context) { | |
|
|
||
| const repoInfo = await fetchRepoInfo(repoUrl); | ||
|
|
||
| let owner; | ||
| let repoName; | ||
| let branch; | ||
|
|
||
| if (repoInfo === null) { | ||
| await say(`:warning: The GitHub repository '${repoUrl}' could not be found (private repo?).`); | ||
| return; | ||
| [owner, repoName] = repoUrl.split('github.com/')[1].split('/'); | ||
| branch = branchInput || 'main'; | ||
|
|
||
| await say(`:warning: GitHub API returned 404 for ${repoUrl}. Adding as private repo with branch: ${branch}`); | ||
| } else { | ||
| if (repoInfo.archived) { | ||
| await say(`:warning: The GitHub repository '${repoUrl}' is archived. Please unarchive it before adding it to a site.`); | ||
| return; | ||
| } | ||
|
|
||
| owner = repoInfo.owner.login; | ||
| repoName = repoInfo.name; | ||
| branch = branchInput || repoInfo.default_branch; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bosschaert Since we are invoking AEMY shall we not get all the info from there itself ? Can we add a JIRA in the backlog for the same. We would need to know the default_branch in the long term. |
||
| } | ||
|
|
||
| if (repoInfo.archived) { | ||
| await say(`:warning: The GitHub repository '${repoUrl}' is archived. Please unarchive it before adding it to a site.`); | ||
| const isOnboarded = await isOnboardedWithAemy(owner, repoName, branch); | ||
| if (!isOnboarded) { | ||
| await say(`:warning: The repository '${repoUrl}' is not onboarded with Aemy. Please onboard it with Aemy before adding it to a site.`); | ||
| return; | ||
| } | ||
|
|
||
| site.setGitHubURL(repoUrl); | ||
| const codeConfig = { | ||
| type: 'github', | ||
| owner: repoInfo.owner.login, | ||
| repo: repoInfo.name, | ||
| ref: repoInfo.default_branch, | ||
| owner, | ||
| repo: repoName, | ||
| ref: branch, | ||
| url: repoUrl, | ||
| }; | ||
| site.setCode(codeConfig); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we read it from an environment variable as done here. You may need to ask in the channel to add the environment variable in the api service.
https://github.com/adobe/spacecat-import-worker/pull/442/files#diff-a4f3f338bc03c3a0a8b82bb5ed97342471ed7c5caf7e74576d342a089e472938R39
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @vdua, I was also thinking the same. Would you also happen to if env variable AEMY_API_KEY is available to spacecat-api-worker or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not have access to check the env variables. Can you check in the slack channel.