internal static async Task Update() { #if DEBUG return; #endif await Task.Run(() => { try { Logger.Info("Checking for a new version of CoolFish"); var latestInfo = GithubAPI.GetLatestVersionId(); if (latestInfo.HasValue) { Logger.Info("A new version of CoolFish was found. Downloading the latest version."); MessageBox.Show("A new version of CoolFish was found. We will now update to the latest version", "Update Required", MessageBoxButtons.OK); GithubAPI.DownloadAsset(latestInfo.Value); Logger.Info("Download Complete."); MessageBox.Show("The download has completed. Please extract the zip file in the CoolFish directory. This application will now close."); BotManager.SafeShutdown(); } else { Logger.Info("No new versions available."); } } catch (Exception ex) { Logger.Warn("Exception thrown while trying to check for a new version", ex); } }); }
internal static async Task Update() { await Task.Run(() => { try { Logger.Info("Checking for a new version of CoolFish"); Tuple <int, string> latestInfo = GithubAPI.GetLatestVersionInfo(); if (latestInfo != null) { Logger.Info("A new version of CoolFish was found. Downloading the latest version."); MessageBox.Show("A new version of CoolFish was found. We will now update to the latest version", "Update Required", MessageBoxButtons.OK); GithubAPI.DownloadAsset(latestInfo.Item1, latestInfo.Item2); } else { Logger.Info("No new versions available."); } } catch (Exception ex) { Logger.Warn("Exception thrown while trying to check for a new version", ex); } }); }
public void Release() { GithubRelease ckan = GithubAPI.GetLatestRelease("KSP-CKAN/Test", false); Assert.IsNotNull(ckan.author); Assert.IsNotNull(ckan.download); Assert.IsNotNull(ckan.size); Assert.IsNotNull(ckan.version); }
public static void DeployFromImage(string cloneName, string deploymentName = null, string branchName = null, string imagePath = null, string destPath = null) { string repoBranch = branchName != null ? branchName : PyRevitLabsConsts.TragetBranch; string imageSource = imagePath != null ? imagePath : GithubAPI.GetBranchArchiveUrl(PyRevitLabsConsts.OriginalRepoId, repoBranch); string imageFilePath = null; // verify image is zip if (!imageSource.ToLower().EndsWith(GithubAPI.ArchiveFileExtension)) { throw new PyRevitException("Clone source must be a ZIP image."); } logger.Debug("Image file is \"{0}\"", imageSource); // determine destination path if not provided if (destPath is null) { destPath = Path.Combine(PyRevitLabsConsts.PyRevitPath, PyRevitConsts.DefaultCopyInstallName); } // check existing destination path if (CommonUtils.VerifyPath(destPath)) { destPath = destPath.NormalizeAsPath(); logger.Debug("Destination path already exists {0}", destPath); destPath = Path.Combine(destPath, cloneName); logger.Debug("Using subpath {0}", destPath); if (CommonUtils.VerifyPath(destPath)) { throw new PyRevitException(string.Format("Destination path already exists \"{0}\"", destPath)); } } logger.Debug("Destination path determined as \"{0}\"", destPath); // process source // decide to download if source is a url if (imageSource.IsValidHttpUrl()) { try { var pkgDest = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), Path.GetFileName(imageSource)); logger.Info("Downloading package \"{0}\"", imageSource); logger.Debug("Downloading package \"{0}\" to \"{1}\"", imageSource, pkgDest); imageFilePath = CommonUtils.DownloadFile(imageSource, pkgDest, progressToken: Path.GetFileName(imageSource)); logger.Debug("Downloaded to \"{0}\"", imageFilePath); } catch (Exception ex) { throw new PyRevitException( string.Format("Error downloading repo image file \"{0}\" | {1}", imageSource, ex.Message) ); } } // otherwise check if the source is a file and exists else if (CommonUtils.VerifyFile(imageSource)) { imageFilePath = imageSource; } // otherwise the source format is unknown else { throw new PyRevitException(string.Format("Unknown source \"{0}\"", imageSource)); } // now extract the file if (imageFilePath != null) { var stagedImage = Path.Combine( Environment.GetEnvironmentVariable("TEMP"), Path.GetFileNameWithoutExtension(imageFilePath) ); // delete existing if (CommonUtils.VerifyPath(stagedImage)) { logger.Debug("Deleting existing temp staging path \"{0}\"", stagedImage); CommonUtils.DeleteDirectory(stagedImage); } // unpack image logger.Info("Preparing package for deployment..."); try { logger.Debug("Staging package to \"{0}\"", stagedImage); ZipFile.ExtractToDirectory(imageFilePath, stagedImage); } catch (Exception ex) { throw new PyRevitException( string.Format("Error unpacking \"{0}\" | {1}", imageFilePath, ex.Message) ); } // make a pyrevit clone and handle deployment try { var clone = new PyRevitClone(stagedImage); // deployment: copy the needed directories logger.Info("Deploying to \"{0}\"", destPath); if (deploymentName != null) { // deploy the requested deployment // throws exceptions if deployment does not exist or on copy error Deploy(clone.ClonePath, deploymentName, destPath); } else { logger.Debug("Deploying complete clone from image..."); CommonUtils.CopyDirectory(clone.ClonePath, destPath); } // cleanup temp files logger.Debug("Cleaning up temp files after clone from image..."); try { CommonUtils.DeleteDirectory(stagedImage); } catch (Exception delEx) { logger.Error(string.Format("Error cleaning up temp staging files \"{0}\" | {1}", destPath, delEx.Message)); } // record image deployment settings try { RecordDeploymentArgs(cloneName, deploymentName, branchName, imagePath, destPath); } catch (Exception ex) { logger.Debug(string.Format("Exception occured after clone from image complete. " + "Deleting clone \"{0}\" | {1}", destPath, ex.Message)); try { CommonUtils.DeleteDirectory(destPath); } catch (Exception delEx) { logger.Error(string.Format("Error post-install cleanup on \"{0}\" | {1}", destPath, delEx.Message)); } // cleanup completed, now baloon up the exception throw ex; } // register the clone VerifyAndRegisterClone(cloneName, destPath); logger.Info("Package deployed and registered."); } catch (PyRevitException ex) { logger.Error("Can not find a valid clone inside extracted package. | {0}", ex.Message); } } else { throw new PyRevitException( string.Format("Unknown error occured getting package from \"{0}\"", imageSource) ); } }
// Find releases public static List <PyRevitRelease> GetReleases() => GithubAPI.GetReleases <PyRevitRelease>(PyRevitLabsConsts.OriginalRepoId).OrderByDescending(r => r.CreatedTimeStamp).ToList();
public GHGetIgnore(String CachePath, Options Flags = Options.None) { flags = Flags; _gh = new GithubAPI(CachePath, flags); }
public async Task <IActionResult> GithubReturn([Required] string code, [Required] string state) { if (!githubConfigured) { return(Problem("Github OAuth is not configured on the server")); } var(session, result) = await FetchAndCheckSessionForSsoReturn(state, OAuthController.GithubCLASource); // Return in case of failure if (result != null) { return(result); } if (session == null) { throw new Exception("Logic error, returned null session without returning an error result"); } var signature = await Database.InProgressClaSignatures.FirstOrDefaultAsync(s => s.SessionId == session.Id); if (signature == null) { return(NotFound("No active signature to authorize against")); } if (string.IsNullOrEmpty(session.SsoReturnUrl)) { return(NotFound("Session not setup with a return URL")); } var accessToken = await GetAccessTokenFromCode(code, session.SsoReturnUrl); // Clear things here already to make sure even on partial failure the request can't be repeated ClearSSOParametersFromSession(session); if (string.IsNullOrEmpty(accessToken)) { return(this.WorkingForbid("Failed to retrieve access token from Github")); } // We got an access token, authentication was successful. Now we can fetch the user data var githubAPI = new GithubAPI(githubLog, accessToken) { ThrowIfNotConfigured = true }; GithubUserInfo?user; List <GithubEmail> emails; try { user = await githubAPI.GetCurrentUserInfo() ?? throw new Exception("Github user data is null"); if (string.IsNullOrWhiteSpace(user.Login) || user.Id == 0) { throw new Exception("Didn't get username or id"); } emails = await githubAPI.GetCurrentUserEmails(); if (emails == null || emails.Count < 1) { throw new Exception("Didn't get user email info"); } } catch (Exception e) { Logger.LogWarning("Failed to get user info from github due to error: {@E}", e); return(this.WorkingForbid("Failed to retrieve user info from Github")); } var email = emails.FirstOrDefault(e => e.Primary && e.Verified) ?? emails.FirstOrDefault(e => e.Verified); if (email == null) { return(this.WorkingForbid("Failed to get any verified email from your Github account")); } // Disallow attaching if this is an account that doesn't need a CLA signature if (claExemptions.IsExempt(user.Login)) { return(this.WorkingForbid( "This Github account is exempt from CLA signing and can't be attached to a signature")); } // We store both username and user id to be able to detect if someone changes their username (as an extra // guarantee) signature.GithubAccount = user.Login; signature.GithubUserId = user.Id; signature.GithubEmail = email.Email; signature.GithubSkipped = false; await Database.SaveChangesAsync(); Logger.LogInformation( "OAuth through Github succeeded, attaching {Login} ({Id1}) to signature of session {Id2}" + " (github email: {GithubEmail})", user.Login, user.Id, session.Id, signature.GithubEmail); return(Redirect("/cla/sign")); }